Initial import
This commit is contained in:
commit
9e20145d24
39
Makefile
Normal file
39
Makefile
Normal file
|
@ -0,0 +1,39 @@
|
|||
PACKAGE = Terminal
|
||||
VERSION = 0.0.0
|
||||
SUBDIRS = src
|
||||
RM ?= rm -f
|
||||
LN ?= ln -f
|
||||
TAR ?= tar -czvf
|
||||
|
||||
|
||||
all: subdirs
|
||||
|
||||
subdirs:
|
||||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE)) || exit; done
|
||||
|
||||
clean:
|
||||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) clean) || exit; done
|
||||
|
||||
distclean:
|
||||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) distclean) || exit; done
|
||||
|
||||
dist:
|
||||
$(RM) -r -- $(PACKAGE)-$(VERSION)
|
||||
$(LN) -s -- . $(PACKAGE)-$(VERSION)
|
||||
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz -- \
|
||||
$(PACKAGE)-$(VERSION)/src/terminal.c \
|
||||
$(PACKAGE)-$(VERSION)/src/main.c \
|
||||
$(PACKAGE)-$(VERSION)/src/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/src/terminal.h \
|
||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/project.conf
|
||||
$(RM) -- $(PACKAGE)-$(VERSION)
|
||||
|
||||
install:
|
||||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) install) || exit; done
|
||||
|
||||
uninstall:
|
||||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) uninstall) || exit; done
|
||||
|
||||
.PHONY: all subdirs clean distclean dist install uninstall
|
10
config.h
Normal file
10
config.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#define PACKAGE "Terminal"
|
||||
#define VERSION "0.0.0"
|
||||
|
||||
#ifndef PREFIX
|
||||
# define PREFIX "/usr/local"
|
||||
#endif
|
||||
|
||||
#ifndef LIBDIR
|
||||
# define LIBDIR PREFIX "/lib"
|
||||
#endif
|
6
project.conf
Normal file
6
project.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
package=Terminal
|
||||
version=0.0.0
|
||||
config=h
|
||||
|
||||
subdirs=src
|
||||
dist=Makefile
|
46
src/Makefile
Normal file
46
src/Makefile
Normal file
|
@ -0,0 +1,46 @@
|
|||
TARGETS = terminal
|
||||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
BINDIR = $(PREFIX)/bin
|
||||
SBINDIR = $(PREFIX)/sbin
|
||||
CC = cc
|
||||
CPPFLAGSF=
|
||||
CPPFLAGS=
|
||||
CFLAGSF = -W `pkg-config --cflags libDesktop`
|
||||
CFLAGS = -Wall -g -O2
|
||||
LDFLAGSF= `pkg-config --libs libDesktop`
|
||||
RM = rm -f
|
||||
LN = ln -f
|
||||
MKDIR = mkdir -m 0755 -p
|
||||
INSTALL = install
|
||||
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
terminal_OBJS = terminal.o main.o
|
||||
terminal_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
terminal_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
||||
terminal: $(terminal_OBJS)
|
||||
$(CC) -o terminal $(terminal_OBJS) $(terminal_LDFLAGS)
|
||||
|
||||
terminal.o: terminal.c terminal.h
|
||||
$(CC) $(terminal_CFLAGS) -c terminal.c
|
||||
|
||||
main.o: main.c terminal.h ../config.h
|
||||
$(CC) $(terminal_CFLAGS) -c main.c
|
||||
|
||||
clean:
|
||||
$(RM) -- $(terminal_OBJS)
|
||||
|
||||
distclean: clean
|
||||
$(RM) -- $(TARGETS)
|
||||
|
||||
install: $(TARGETS)
|
||||
$(MKDIR) $(DESTDIR)$(BINDIR)
|
||||
$(INSTALL) -m 0755 -- terminal $(DESTDIR)$(BINDIR)/terminal
|
||||
|
||||
uninstall:
|
||||
$(RM) -- $(DESTDIR)$(BINDIR)/terminal
|
||||
|
||||
.PHONY: all clean distclean install uninstall
|
16
src/project.conf
Normal file
16
src/project.conf
Normal file
|
@ -0,0 +1,16 @@
|
|||
targets=terminal
|
||||
cflags_force=-W `pkg-config --cflags libDesktop`
|
||||
cflags=-Wall -g -O2
|
||||
ldflags_force=`pkg-config --libs libDesktop`
|
||||
dist=Makefile,terminal.h
|
||||
|
||||
[terminal]
|
||||
type=binary
|
||||
sources=terminal.c,main.c
|
||||
install=$(BINDIR)
|
||||
|
||||
[terminal.c]
|
||||
depends=terminal.h
|
||||
|
||||
[main.c]
|
||||
depends=terminal.h,../config.h
|
142
src/terminal.c
Normal file
142
src/terminal.c
Normal file
|
@ -0,0 +1,142 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2012-2013 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Terminal */
|
||||
/* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <System.h>
|
||||
#include "terminal.h"
|
||||
|
||||
|
||||
/* Terminal */
|
||||
/* private */
|
||||
/* types */
|
||||
typedef struct _TerminalTab TerminalTab;
|
||||
|
||||
struct _Terminal
|
||||
{
|
||||
/* internal */
|
||||
TerminalTab * tabs;
|
||||
size_t tabs_cnt;
|
||||
|
||||
/* widgets */
|
||||
GtkWidget * window;
|
||||
GtkWidget * notebook;
|
||||
};
|
||||
|
||||
struct _TerminalTab
|
||||
{
|
||||
GtkWidget * label;
|
||||
GtkWidget * socket;
|
||||
GPid pid;
|
||||
};
|
||||
|
||||
|
||||
/* prototypes */
|
||||
/* callbacks */
|
||||
static gboolean _terminal_on_closex(gpointer data);
|
||||
|
||||
|
||||
/* public */
|
||||
/* functions */
|
||||
/* terminal_new */
|
||||
Terminal * terminal_new(void)
|
||||
{
|
||||
Terminal * terminal;
|
||||
GtkWidget * vbox;
|
||||
GtkWidget * widget;
|
||||
char * argv[] = { "xterm", "-into", NULL, NULL };
|
||||
char buf[16];
|
||||
GError * error = NULL;
|
||||
|
||||
if((terminal = object_new(sizeof(*terminal))) == NULL)
|
||||
return NULL;
|
||||
/* FIXME really implement */
|
||||
terminal->tabs = malloc(sizeof(*terminal->tabs));
|
||||
terminal->tabs_cnt = 1;
|
||||
terminal->window = NULL;
|
||||
/* check for errors */
|
||||
if(terminal->tabs == NULL)
|
||||
{
|
||||
terminal_delete(terminal);
|
||||
return NULL;
|
||||
}
|
||||
/* widgets */
|
||||
terminal->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_default_size(GTK_WINDOW(terminal->window), 400, 200);
|
||||
gtk_window_set_title(GTK_WINDOW(terminal->window), "Terminal");
|
||||
g_signal_connect_swapped(terminal->window, "delete-event", G_CALLBACK(
|
||||
_terminal_on_closex), terminal);
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
/* menu bar */
|
||||
widget = gtk_menu_bar_new();
|
||||
gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, TRUE, 0);
|
||||
/* view */
|
||||
terminal->notebook = gtk_notebook_new();
|
||||
gtk_box_pack_start(GTK_BOX(vbox), terminal->notebook, TRUE, TRUE, 0);
|
||||
/* first tab */
|
||||
terminal->tabs->socket = gtk_socket_new();
|
||||
terminal->tabs->label = gtk_label_new("xterm");
|
||||
gtk_notebook_append_page(GTK_NOTEBOOK(terminal->notebook),
|
||||
terminal->tabs->socket, terminal->tabs->label);
|
||||
gtk_container_add(GTK_CONTAINER(terminal->window), vbox);
|
||||
gtk_widget_show_all(vbox);
|
||||
/* launch xterm */
|
||||
snprintf(buf, sizeof(buf), "%u", gtk_socket_get_id(
|
||||
GTK_SOCKET(terminal->tabs->socket)));
|
||||
argv[2] = buf;
|
||||
if(g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
|
||||
&terminal->tabs->pid, &error) == FALSE)
|
||||
{
|
||||
fprintf(stderr, "%s: %s: %s\n", "Terminal", argv[0],
|
||||
error->message);
|
||||
g_error_free(error);
|
||||
terminal_delete(terminal);
|
||||
return NULL;
|
||||
}
|
||||
gtk_widget_show(terminal->window);
|
||||
return terminal;
|
||||
}
|
||||
|
||||
|
||||
/* terminal_delete */
|
||||
void terminal_delete(Terminal * terminal)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < terminal->tabs_cnt; i++)
|
||||
if(terminal->tabs[i].pid > 0)
|
||||
g_spawn_close_pid(terminal->tabs[i].pid);
|
||||
/* FIXME also take care of the sub-processes */
|
||||
if(terminal->window != NULL)
|
||||
gtk_widget_destroy(terminal->window);
|
||||
free(terminal->tabs);
|
||||
object_delete(terminal);
|
||||
}
|
||||
|
||||
|
||||
/* private */
|
||||
/* functions */
|
||||
/* callbacks */
|
||||
/* terminal_on_closex */
|
||||
static gboolean _terminal_on_closex(gpointer data)
|
||||
{
|
||||
Terminal * terminal = data;
|
||||
|
||||
gtk_widget_hide(terminal->window);
|
||||
gtk_main_quit();
|
||||
return TRUE;
|
||||
}
|
33
src/terminal.h
Normal file
33
src/terminal.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Terminal */
|
||||
/* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
|
||||
#ifndef TERMINAL_TERMINAL_H
|
||||
# define TERMINAL_TERMINAL_H
|
||||
|
||||
|
||||
/* Terminal */
|
||||
/* public */
|
||||
/* types */
|
||||
typedef struct _Terminal Terminal;
|
||||
|
||||
|
||||
/* functions */
|
||||
/* essential */
|
||||
Terminal * terminal_new(void);
|
||||
void terminal_delete(Terminal * terminal);
|
||||
|
||||
#endif /* !TERMINAL_TERMINAL_H */
|
Loading…
Reference in New Issue
Block a user