From 2b7df6f059bedc0387e6d06c2df56cb488ee4cfa Mon Sep 17 00:00:00 2001 From: mallum Date: Fri, 28 Jan 2005 21:37:07 +0000 Subject: Run through indent git-svn-id: http://svn.o-hand.com/repos/matchbox/trunk/Xoo@1051 b067294f-1dea-0310-9683-c47a78595994 --- ChangeLog | 14 ++ src/button.c | 60 +++---- src/callbacks.c | 92 +++++++---- src/callbacks.h | 30 ++-- src/config.c | 287 +++++++++++++++++---------------- src/fakedev.h | 79 +++++---- src/keys.c | 64 ++++---- src/main.c | 492 +++++++++++++++++++++++++++++++------------------------- src/prefs.c | 54 ++++--- src/prefs.h | 14 +- 10 files changed, 647 insertions(+), 539 deletions(-) diff --git a/ChangeLog b/ChangeLog index 10170fe..9e80e3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-01-28 mallum,,, + + * src/button.c: + * src/callbacks.c: (on_about_activate), (on_delete_event_hide), + (on_select_device): + * src/callbacks.h: + * src/config.c: (config_get_val): + * src/fakedev.h: + * src/keys.c: (keys_xnest_connect): + * src/main.c: (fakeapp_new), (fakeapp_create_gui): + * src/prefs.c: (on_prefs_apply_clicked): + * src/prefs.h: + Just run through gnu indent. + 2005-01-28 mallum,,, * configure.ac: diff --git a/src/button.c b/src/button.c index eeec5a1..2c52eba 100644 --- a/src/button.c +++ b/src/button.c @@ -20,36 +20,31 @@ #include #include "fakedev.h" -FakeButton* -button_new(FakeApp *app, - int x, - int y, - int width, - int height, - KeySym ks, - int repeat, - GdkPixbuf *img) +FakeButton * +button_new (FakeApp * app, + int x, + int y, + int width, int height, KeySym ks, int repeat, GdkPixbuf * img) { - FakeButton *button = malloc(sizeof(FakeButton)); - memset(button, 0, sizeof(FakeButton)); + FakeButton *button = malloc (sizeof (FakeButton)); + memset (button, 0, sizeof (FakeButton)); button->app = app; button->x = x; button->y = y; button->height = height; - button->width = width; + button->width = width; button->keysym = ks; - button->overlay = img; + button->overlay = img; button->repeat = repeat; if (img) { - if (gdk_pixbuf_get_width(img) != button->width - || gdk_pixbuf_get_height(img) != button->height) + if (gdk_pixbuf_get_width (img) != button->width + || gdk_pixbuf_get_height (img) != button->height) { - fprintf(stderr, - "** warning: Button image size does not equal defined button size.\n" - ); + fprintf (stderr, + "** warning: Button image size does not equal defined button size.\n"); } } @@ -60,34 +55,39 @@ button_new(FakeApp *app, } #if 0 -FakeButton* -button_find_from_win(FakeApp *app, Window xevent_window_id) +FakeButton * +button_find_from_win (FakeApp * app, Window xevent_window_id) { FakeButton *button; - for (button = app->button_head; button; button=button->next) + for (button = app->button_head; button; button = button->next) if (button->win == xevent_window_id) return button; return NULL; - -} +} #endif -void button_press(GtkWidget *w, GdkEventButton *event, FakeButton *button) { +void +button_press (GtkWidget * w, GdkEventButton * event, FakeButton * button) +{ g_return_if_fail (button != NULL); - gtk_image_set_from_pixmap (GTK_IMAGE(button->image), button->active_img, NULL); - keys_send_key(button->app, button->keysym, KEYDOWN); + gtk_image_set_from_pixmap (GTK_IMAGE (button->image), button->active_img, + NULL); + keys_send_key (button->app, button->keysym, KEYDOWN); } -void button_release(GtkWidget *w, GdkEventButton *event, FakeButton *button) { +void +button_release (GtkWidget * w, GdkEventButton * event, FakeButton * button) +{ g_return_if_fail (button != NULL); - gtk_image_set_from_pixmap (GTK_IMAGE(button->image), button->normal_img, NULL); - keys_send_key(button->app, button->keysym, KEYUP); + gtk_image_set_from_pixmap (GTK_IMAGE (button->image), button->normal_img, + NULL); + keys_send_key (button->app, button->keysym, KEYUP); } void -button_activate(FakeApp *app, FakeButton *button) +button_activate (FakeApp * app, FakeButton * button) { ; } diff --git a/src/callbacks.c b/src/callbacks.c index 7a17953..0e9501f 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -26,65 +26,89 @@ extern pid_t xnest_pid; -void on_send_signal_activate (GtkMenuItem *menuitem, FakeApp *app) { +void +on_send_signal_activate (GtkMenuItem * menuitem, FakeApp * app) +{ g_return_if_fail (app->xnest_pid != 0); kill (app->xnest_pid, SIGUSR1); } -static void quit (FakeApp *app) { +static void +quit (FakeApp * app) +{ kill (app->xnest_pid, SIGKILL); gtk_main_quit (); } -void on_quit_activate (GtkMenuItem *menuitem, FakeApp *app) { +void +on_quit_activate (GtkMenuItem * menuitem, FakeApp * app) +{ quit (app); } -void on_window_destroy (GtkObject *object, FakeApp *app) { +void +on_window_destroy (GtkObject * object, FakeApp * app) +{ quit (app); } -gboolean on_popup_menu_show (GtkWidget *widget, GdkEventButton *event, FakeApp *app) { - if (event->button == 3) { - gtk_menu_popup (GTK_MENU (app->popupmenu), NULL, NULL, NULL, NULL, event->button, event->time); - return TRUE; - } +gboolean +on_popup_menu_show (GtkWidget * widget, GdkEventButton * event, FakeApp * app) +{ + if (event->button == 3) + { + gtk_menu_popup (GTK_MENU (app->popupmenu), NULL, NULL, NULL, NULL, + event->button, event->time); + return TRUE; + } return FALSE; } -void on_show_decorations_toggle (GtkCheckMenuItem *menuitem, FakeApp *app) { - if (gtk_window_get_decorated (GTK_WINDOW (app->window))) { - GdkBitmap *mask; - mask = gdk_pixmap_new (app->fixed->window, app->device_width, app->device_height, 1); - gdk_pixbuf_render_threshold_alpha (app->device_img, mask, 0, 0, 0, 0, -1, -1, 128); - gtk_widget_realize(app->window); - gdk_window_shape_combine_mask (app->window->window, mask, 0, 0); - - gtk_window_set_decorated (GTK_WINDOW (app->window), FALSE); - gtk_check_menu_item_set_active (menuitem, FALSE); - } else { - gdk_window_shape_combine_mask (app->window->window, NULL, 0, 0); - gtk_window_set_decorated (GTK_WINDOW (app->window), TRUE); - gtk_check_menu_item_set_active (menuitem, TRUE); - } +void +on_show_decorations_toggle (GtkCheckMenuItem * menuitem, FakeApp * app) +{ + if (gtk_window_get_decorated (GTK_WINDOW (app->window))) + { + GdkBitmap *mask; + mask = + gdk_pixmap_new (app->fixed->window, app->device_width, + app->device_height, 1); + gdk_pixbuf_render_threshold_alpha (app->device_img, mask, 0, 0, 0, 0, + -1, -1, 128); + gtk_widget_realize (app->window); + gdk_window_shape_combine_mask (app->window->window, mask, 0, 0); + + gtk_window_set_decorated (GTK_WINDOW (app->window), FALSE); + gtk_check_menu_item_set_active (menuitem, FALSE); + } + else + { + gdk_window_shape_combine_mask (app->window->window, NULL, 0, 0); + gtk_window_set_decorated (GTK_WINDOW (app->window), TRUE); + gtk_check_menu_item_set_active (menuitem, TRUE); + } } -void on_about_activate (GtkMenuItem *menuitem, FakeApp *app) { +void +on_about_activate (GtkMenuItem * menuitem, FakeApp * app) +{ gtk_window_present (GTK_WINDOW (app->about_window)); } -gboolean on_delete_event_hide (GtkWidget *widget, GdkEvent *event, FakeApp *app) { +gboolean +on_delete_event_hide (GtkWidget * widget, GdkEvent * event, FakeApp * app) +{ gtk_widget_hide (widget); return TRUE; } -void -on_select_device (GtkMenuItem *menuitem, FakeApp *app) +void +on_select_device (GtkMenuItem * menuitem, FakeApp * app) { GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new ("Open Device", - GTK_WINDOW(app->window), + GTK_WINDOW (app->window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, @@ -94,18 +118,18 @@ on_select_device (GtkMenuItem *menuitem, FakeApp *app) { char *filename; - + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); /****** DONT TRY THIS AT HOME KIDS. *******/ /* xxx FIXME, This is gross - just a very nasty hack for now xxx */ - kill(xnest_pid, 9); - sleep(2); - execl("/bin/sh", "sh", "-c", "Xoo", "--device", filename, 0); + kill (xnest_pid, 9); + sleep (2); + execl ("/bin/sh", "sh", "-c", "Xoo", "--device", filename, 0); - g_warning("Failed load device %s\n", filename); + g_warning ("Failed load device %s\n", filename); g_free (filename); } diff --git a/src/callbacks.h b/src/callbacks.h index e3e4887..3749981 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -2,29 +2,23 @@ /* GTK+ callbacks */ -void -on_send_signal_activate (GtkWidget *menuitem, FakeApp *app); +void on_send_signal_activate (GtkWidget * menuitem, FakeApp * app); -void -on_preferences_activate (GtkMenuItem *menuitem, FakeApp *app); +void on_preferences_activate (GtkMenuItem * menuitem, FakeApp * app); -void -on_quit_activate (GtkMenuItem *menuitem, FakeApp *app); +void on_quit_activate (GtkMenuItem * menuitem, FakeApp * app); -void -on_about_activate (GtkMenuItem *menuitem, FakeApp *app); +void on_about_activate (GtkMenuItem * menuitem, FakeApp * app); -void -on_window_destroy (GtkObject *widget, FakeApp *app); +void on_window_destroy (GtkObject * widget, FakeApp * app); -gboolean -on_popup_menu_show (GtkWidget *widget, GdkEventButton *event, FakeApp *app); +gboolean +on_popup_menu_show (GtkWidget * widget, GdkEventButton * event, + FakeApp * app); -void -on_show_decorations_toggle (GtkMenuItem *menuitem, FakeApp *app); +void on_show_decorations_toggle (GtkMenuItem * menuitem, FakeApp * app); -gboolean -on_delete_event_hide (GtkWidget *widget, GdkEvent *event, FakeApp *app); +gboolean +on_delete_event_hide (GtkWidget * widget, GdkEvent * event, FakeApp * app); -void -on_select_device (GtkMenuItem *menuitem, FakeApp *app); +void on_select_device (GtkMenuItem * menuitem, FakeApp * app); diff --git a/src/config.c b/src/config.c index 71210b9..7a81546 100644 --- a/src/config.c +++ b/src/config.c @@ -23,48 +23,50 @@ #include #include #include -#include /* dirname() */ +#include /* dirname() */ #include #include #include "fakedev.h" -unsigned char* -config_load_file(const char* filename) +unsigned char * +config_load_file (const char *filename) { - struct stat st; - FILE* fp; - unsigned char* str; - int len; - char tmp[1024]; - - strncpy(tmp, filename, 1024); - - if (stat(tmp, &st)) + struct stat st; + FILE *fp; + unsigned char *str; + int len; + char tmp[1024]; + + strncpy (tmp, filename, 1024); + + if (stat (tmp, &st)) { - snprintf(tmp, 1024, "%s.xml", filename); - if (stat(tmp, &st)) + snprintf (tmp, 1024, "%s.xml", filename); + if (stat (tmp, &st)) { - snprintf(tmp, 1024, PKGDATADIR "/%s", filename); - if (stat(tmp, &st)) + snprintf (tmp, 1024, PKGDATADIR "/%s", filename); + if (stat (tmp, &st)) { - snprintf(tmp, 1024, PKGDATADIR "/%s.xml", filename); - if (stat(tmp, &st)) + snprintf (tmp, 1024, PKGDATADIR "/%s.xml", filename); + if (stat (tmp, &st)) return NULL; } } - } + } + + if (!(fp = fopen (tmp, "rb"))) + return NULL; - if (!(fp = fopen(tmp, "rb"))) return NULL; - /* Read in the file. */ - str = malloc(sizeof(char)*(st.st_size + 1)); - len = fread(str, 1, st.st_size, fp); - if (len >= 0) str[len] = '\0'; - - fclose(fp); - + str = malloc (sizeof (char) * (st.st_size + 1)); + len = fread (str, 1, st.st_size, fp); + if (len >= 0) + str[len] = '\0'; + + fclose (fp); + /* change to the same directory as the conf file - for images */ - chdir(dirname(tmp)); + chdir (dirname (tmp)); return str; } @@ -72,270 +74,275 @@ static const char * config_get_val (char *key, const char **attr) { int i = 0; - + while (attr[i] != NULL) { - if (!strcmp(attr[i], key)) - return attr[i+1]; + if (!strcmp (attr[i], key)) + return attr[i + 1]; i += 2; } - + return NULL; } -static GdkPixbuf* -config_load_image (FakeApp *app, const char *filename) +static GdkPixbuf * +config_load_image (FakeApp * app, const char *filename) { GError *error = NULL; GdkPixbuf *pixbuf; - char tmp[1024]; - struct stat st; + char tmp[1024]; + struct stat st; - strncpy(tmp, filename, 1024); - - if (stat(tmp, &st)) + strncpy (tmp, filename, 1024); + + if (stat (tmp, &st)) { - snprintf(tmp, 1024, PKGDATADIR "/%s", filename); - if (stat(tmp, &st)) + snprintf (tmp, 1024, PKGDATADIR "/%s", filename); + if (stat (tmp, &st)) { return NULL; } } - pixbuf = gdk_pixbuf_new_from_file(tmp, &error); - if (error == NULL) { - return pixbuf; - } else { - g_warning ("Could not load %s: %s", filename, error->message); - g_error_free (error); - return NULL; - } + pixbuf = gdk_pixbuf_new_from_file (tmp, &error); + if (error == NULL) + { + return pixbuf; + } + else + { + g_warning ("Could not load %s: %s", filename, error->message); + g_error_free (error); + return NULL; + } } static int -config_handle_button_tag(FakeApp *app, const char **attr) +config_handle_button_tag (FakeApp * app, const char **attr) { - const char *s; - FakeButton *button; - int x,y,width,height; - KeySym keysym; - int repeat = 1; + const char *s; + FakeButton *button; + int x, y, width, height; + KeySym keysym; + int repeat = 1; GdkPixbuf *img = NULL; if ((s = config_get_val ("width", attr)) == NULL) - { - fprintf(stderr, "Error: 'button' tag missing width param"); + { + fprintf (stderr, "Error: 'button' tag missing width param"); return 0; } - width = atoi(s); + width = atoi (s); if ((s = config_get_val ("height", attr)) == NULL) - { - fprintf(stderr, "Error: 'button' tag missing height param"); + { + fprintf (stderr, "Error: 'button' tag missing height param"); return 0; } - height = atoi(s); + height = atoi (s); if ((s = config_get_val ("x", attr)) == NULL) - { - fprintf(stderr, "Error: 'button' tag missing x param"); + { + fprintf (stderr, "Error: 'button' tag missing x param"); return 0; } - x = atoi(s); + x = atoi (s); if ((s = config_get_val ("y", attr)) == NULL) - { - fprintf(stderr, "Error: 'button' tag missing y param"); + { + fprintf (stderr, "Error: 'button' tag missing y param"); return 0; } - y = atoi(s); + y = atoi (s); if ((s = config_get_val ("key", attr)) == NULL) - { - fprintf(stderr, "Error: 'button' tag missing key param"); + { + fprintf (stderr, "Error: 'button' tag missing key param"); return 0; } - if ((keysym = XStringToKeysym(s)) == NoSymbol) + if ((keysym = XStringToKeysym (s)) == NoSymbol) { - fprintf(stderr, "Error: Cant find keysym for '%s'", s); + fprintf (stderr, "Error: Cant find keysym for '%s'", s); return 0; } /* optional attributes */ if ((s = config_get_val ("img", attr)) != NULL) - { + { if ((img = config_load_image (app, s)) == NULL) { - fprintf(stderr, "Error: Falied to load '%s' image.", s); + fprintf (stderr, "Error: Falied to load '%s' image.", s); } } - if ( ((s = config_get_val ("repeat", attr)) != NULL) - && !strcasecmp(s, "off") ) + if (((s = config_get_val ("repeat", attr)) != NULL) + && !strcasecmp (s, "off")) repeat = 0; if (app->button_head == NULL) - app->button_head = button_new(app, x, y, width, height, - keysym, repeat, img); + app->button_head = button_new (app, x, y, width, height, + keysym, repeat, img); else { - for (button = app->button_head; button->next; button=button->next) ; - button->next = button_new(app, x, y, width, height, - keysym, repeat, img); - } + for (button = app->button_head; button->next; button = button->next); + button->next = button_new (app, x, y, width, height, + keysym, repeat, img); + } return 1; } static int -config_handle_device_tag(FakeApp *app, const char **attr) +config_handle_device_tag (FakeApp * app, const char **attr) { /* width, height, display_width, display_height, display_x, displa_y - */ + */ const char *s; if ((s = config_get_val ("width", attr)) == NULL) - { - fprintf(stderr, "Error: 'device' tag missing width param"); + { + fprintf (stderr, "Error: 'device' tag missing width param"); return 0; } - app->device_width = atoi(s); + app->device_width = atoi (s); if ((s = config_get_val ("height", attr)) == NULL) - { - fprintf(stderr, "Error: 'device' tag missing height param"); + { + fprintf (stderr, "Error: 'device' tag missing height param"); return 0; } - app->device_height = atoi(s); + app->device_height = atoi (s); if ((s = config_get_val ("display_width", attr)) == NULL) - { - fprintf(stderr, "Error: 'device' tag missing display_width param"); + { + fprintf (stderr, "Error: 'device' tag missing display_width param"); return 0; } - app->device_display_width = atoi(s); + app->device_display_width = atoi (s); if ((s = config_get_val ("display_height", attr)) == NULL) - { - fprintf(stderr, "Error: 'device' tag missing display_height param"); + { + fprintf (stderr, "Error: 'device' tag missing display_height param"); return 0; } - app->device_display_height = atoi(s); + app->device_display_height = atoi (s); if ((s = config_get_val ("display_x", attr)) == NULL) - { - fprintf(stderr, "Error: 'device' tag missing display_x param"); + { + fprintf (stderr, "Error: 'device' tag missing display_x param"); return 0; } - app->device_display_x = atoi(s); + app->device_display_x = atoi (s); if ((s = config_get_val ("display_y", attr)) == NULL) - { - fprintf(stderr, "Error: 'device' tag missing display_x param"); + { + fprintf (stderr, "Error: 'device' tag missing display_x param"); return 0; } - app->device_display_y = atoi(s); + app->device_display_y = atoi (s); if ((s = config_get_val ("img", attr)) == NULL) - { - fprintf(stderr, "Error: 'device' tag missing img param"); + { + fprintf (stderr, "Error: 'device' tag missing img param"); return 0; } if ((app->device_img = config_load_image (app, s)) == NULL) { - fprintf(stderr, "Error: Falied to load '%s' image.", s); + fprintf (stderr, "Error: Falied to load '%s' image.", s); return 0; } return 1; } -static void -config_xml_start_cb(void *data, const char *tag, const char **attr) +static void +config_xml_start_cb (void *data, const char *tag, const char **attr) { - FakeApp *app = (FakeApp *)data; + FakeApp *app = (FakeApp *) data; - if (!strcmp(tag, "button")) + if (!strcmp (tag, "button")) { - if (!config_handle_button_tag(app, attr)) + if (!config_handle_button_tag (app, attr)) { - fprintf(stderr, "Giving up.\n"); - exit(1); + fprintf (stderr, "Giving up.\n"); + exit (1); } } - else if (!strcmp(tag, "device")) + else if (!strcmp (tag, "device")) { - if (!config_handle_device_tag(app, attr)) + if (!config_handle_device_tag (app, attr)) { - fprintf(stderr, "Giving up.\n"); - exit(1); + fprintf (stderr, "Giving up.\n"); + exit (1); } } } int -config_init(FakeApp *app, char *conf_file) +config_init (FakeApp * app, char *conf_file) { unsigned char *data; - XML_Parser p; + XML_Parser p; - if ((data = config_load_file(conf_file)) == NULL) + if ((data = config_load_file (conf_file)) == NULL) { - fprintf(stderr, "Couldn't find '%s' device config file\n", conf_file); - exit(1); + fprintf (stderr, "Couldn't find '%s' device config file\n", conf_file); + exit (1); } - p = XML_ParserCreate(NULL); + p = XML_ParserCreate (NULL); - if (! p) { - fprintf(stderr, "Couldn't allocate memory for XML parser\n"); - exit(1); - } + if (!p) + { + fprintf (stderr, "Couldn't allocate memory for XML parser\n"); + exit (1); + } - XML_SetElementHandler(p, config_xml_start_cb, NULL); + XML_SetElementHandler (p, config_xml_start_cb, NULL); /* XML_SetCharacterDataHandler(p, chars); */ - XML_SetUserData(p, (void *)app); + XML_SetUserData (p, (void *) app); + + if (!XML_Parse (p, data, strlen (data), 1)) + { + fprintf (stderr, "XML Parse error at line %d:\n%s\n", + XML_GetCurrentLineNumber (p), + XML_ErrorString (XML_GetErrorCode (p))); + exit (1); + } - if (! XML_Parse(p, data, strlen(data), 1)) { - fprintf(stderr, "XML Parse error at line %d:\n%s\n", - XML_GetCurrentLineNumber(p), - XML_ErrorString(XML_GetErrorCode(p))); - exit(1); - } - return 1; } void -config_reinit(FakeApp *app, char *conf_file) +config_reinit (FakeApp * app, char *conf_file) { /* Save these so we can figure out if server needs restarting */ /* - int prev_device_display_x = app->device_display_x; - int prev_device_display_y = app->device_display_y; - int prev_device_display_width = app->device_display_width; - int prev_device_display_height = app->device_display_height; - */ + int prev_device_display_x = app->device_display_x; + int prev_device_display_y = app->device_display_y; + int prev_device_display_width = app->device_display_width; + int prev_device_display_height = app->device_display_height; + */ /* XXX TODO: Free up our old structure images etc XXX */ diff --git a/src/fakedev.h b/src/fakedev.h index 1339c28..c1d4823 100644 --- a/src/fakedev.h +++ b/src/fakedev.h @@ -45,77 +45,74 @@ struct FakeApp GtkWidget *entry_display, *entry_server, *entry_options, *entry_start; GtkWidget *about_window; - int device_width; - int device_height; + int device_width; + int device_height; - int device_display_x; - int device_display_y; - int device_display_width; - int device_display_height; + int device_display_x; + int device_display_y; + int device_display_width; + int device_display_height; GdkPixbuf *device_img; /* Button stuff */ - - FakeButton *button_head; /* TODO: GList */ - struct timeval key_rep_init_timeout; - struct timeval key_rep_timeout; + FakeButton *button_head; /* TODO: GList */ + + struct timeval key_rep_init_timeout; + struct timeval key_rep_timeout; /* Xnest */ - Display *xnest_dpy; - Window xnest_window; - char *xnest_dpy_name; - char *xnest_bin_path; - char *xnest_bin_options; - pid_t xnest_pid; - - char *win_title; - char *start_cmd; - - int argc; - char **argv; + Display *xnest_dpy; + Window xnest_window; + char *xnest_dpy_name; + char *xnest_bin_path; + char *xnest_bin_options; + pid_t xnest_pid; + + char *win_title; + char *start_cmd; + + int argc; + char **argv; }; struct FakeButton { FakeApp *app; GtkWidget *image; - - int x,y; - int width,height; - KeySym keysym; + int x, y; + int width, height; + + KeySym keysym; GdkPixbuf *overlay; GdkPixmap *normal_img, *active_img; - int repeat; + int repeat; - FakeButton *next; + FakeButton *next; }; -int -config_init(FakeApp *app, char *conf_file); +int config_init (FakeApp * app, char *conf_file); /* buttons */ -FakeButton* -button_new(FakeApp *app, int x, int y, int width, int height, KeySym ks, int reepreat, GdkPixbuf *img); +FakeButton *button_new (FakeApp * app, int x, int y, int width, int height, + KeySym ks, int reepreat, GdkPixbuf * img); -FakeButton* -button_find_from_win(FakeApp *app, Window xevent_window_id); +FakeButton *button_find_from_win (FakeApp * app, Window xevent_window_id); void -button_press(GtkWidget *w, GdkEventButton *event, FakeButton *button); +button_press (GtkWidget * w, GdkEventButton * event, FakeButton * button); void -button_release(GtkWidget *w, GdkEventButton *event, FakeButton *button); +button_release (GtkWidget * w, GdkEventButton * event, FakeButton * button); -void -button_activate(FakeApp *app, FakeButton *button); +void button_activate (FakeApp * app, FakeButton * button); /* keys */ @@ -124,10 +121,8 @@ button_activate(FakeApp *app, FakeButton *button); #define KEYUP 2 #define KEYUPDOWN 3 -int -keys_init(FakeApp *app); +int keys_init (FakeApp * app); -void -keys_send_key(FakeApp *app, KeySym ks, int key_direction); +void keys_send_key (FakeApp * app, KeySym ks, int key_direction); #endif /* _FAKEDEV_H */ diff --git a/src/keys.c b/src/keys.c index ae38e7c..de921c5 100644 --- a/src/keys.c +++ b/src/keys.c @@ -20,31 +20,37 @@ #include static int -keys_xnest_connect(FakeApp *app) +keys_xnest_connect (FakeApp * app) { int trys = 10; - do + do { - if (--trys < 0) return 0; + if (--trys < 0) + return 0; - sleep(1); /* Sleep for a second to give Xnest a chance to start */ + sleep (1); /* Sleep for a second to give Xnest a chance to start */ - app->xnest_dpy = XOpenDisplay(app->xnest_dpy_name); + app->xnest_dpy = XOpenDisplay (app->xnest_dpy_name); { - int num_children; - Window root, parent; - Window *windows; - XQueryTree (GDK_WINDOW_XDISPLAY (app->winnest->window), GDK_WINDOW_XWINDOW(app->winnest->window), &root, &parent, &windows, &num_children); - if (num_children != 0) { - app->xnest_window = windows[0]; - XFree (windows); - } else { - app->xnest_window = 0; - } + int num_children; + Window root, parent; + Window *windows; + XQueryTree (GDK_WINDOW_XDISPLAY (app->winnest->window), + GDK_WINDOW_XWINDOW (app->winnest->window), &root, &parent, + &windows, &num_children); + if (num_children != 0) + { + app->xnest_window = windows[0]; + XFree (windows); + } + else + { + app->xnest_window = 0; + } } } - while ( app->xnest_dpy == NULL ); + while (app->xnest_dpy == NULL); if (app->xnest_window == 0) { @@ -55,43 +61,45 @@ keys_xnest_connect(FakeApp *app) return 1; } -void -keys_send_key(FakeApp *app, KeySym keysym, int key_direction) +void +keys_send_key (FakeApp * app, KeySym keysym, int key_direction) { KeyCode character; - character = XKeysymToKeycode(app->xnest_dpy, keysym); + character = XKeysymToKeycode (app->xnest_dpy, keysym); switch (key_direction) { case KEYDOWN: - XTestFakeKeyEvent(app->xnest_dpy, (unsigned int) character, True, 0); + XTestFakeKeyEvent (app->xnest_dpy, (unsigned int) character, True, 0); break; case KEYUP: - XTestFakeKeyEvent(app->xnest_dpy, (unsigned int) character, False, 0); + XTestFakeKeyEvent (app->xnest_dpy, (unsigned int) character, False, 0); break; case KEYUPDOWN: - XTestFakeKeyEvent(app->xnest_dpy, (unsigned int) character, False, 0); - XTestFakeKeyEvent(app->xnest_dpy, (unsigned int) character, True, 0); + XTestFakeKeyEvent (app->xnest_dpy, (unsigned int) character, False, 0); + XTestFakeKeyEvent (app->xnest_dpy, (unsigned int) character, True, 0); break; } /* Make sure the event gets sent */ - XFlush(app->xnest_dpy); + XFlush (app->xnest_dpy); } int -keys_init(FakeApp *app) +keys_init (FakeApp * app) { int event, error; int major, minor; - if (keys_xnest_connect(app)) + if (keys_xnest_connect (app)) { - if (!XTestQueryExtension(app->xnest_dpy, &event, &error, &major, &minor)) + if (!XTestQueryExtension + (app->xnest_dpy, &event, &error, &major, &minor)) { - g_warning ("XTest extension not supported on server \"%s\"\n.", DisplayString(app->xnest_dpy)); + g_warning ("XTest extension not supported on server \"%s\"\n.", + DisplayString (app->xnest_dpy)); return 0; } diff --git a/src/main.c b/src/main.c index 35ae6e8..3c130d0 100644 --- a/src/main.c +++ b/src/main.c @@ -31,65 +31,65 @@ /* Used by the signal handler to detect which child has died */ pid_t xnest_pid; -static gboolean key_event (GtkWidget *widget, GdkEventKey *event, FakeApp *app); +static gboolean key_event (GtkWidget * widget, GdkEventKey * event, + FakeApp * app); -static void -fakeapp_catch_sigchild(int sign); +static void fakeapp_catch_sigchild (int sign); -FakeApp* -fakeapp_new(void) +FakeApp * +fakeapp_new (void) { GladeXML *glade; - FakeApp *app = g_new0(FakeApp, 1); + FakeApp *app = g_new0 (FakeApp, 1); app->xnest_dpy_name = ":1"; - app->xnest_bin_path = XNEST_BIN ; - app->xnest_bin_options = strdup("-ac"); /* freed if changed */ + app->xnest_bin_path = XNEST_BIN; + app->xnest_bin_options = strdup ("-ac"); /* freed if changed */ app->key_rep_init_timeout.tv_usec = 0; - app->key_rep_init_timeout.tv_sec = 1; + app->key_rep_init_timeout.tv_sec = 1; - app->key_rep_timeout.tv_usec = 40000; - app->key_rep_timeout.tv_sec = 0; + app->key_rep_timeout.tv_usec = 40000; + app->key_rep_timeout.tv_sec = 0; - app->win_title = "Xoo"; + app->win_title = "Xoo"; glade = glade_xml_new (PKGDATADIR "/Xoo.glade", NULL, NULL); g_assert (glade != NULL); - - glade_xml_signal_connect_data (glade, "on_send_signal_activate", - (GCallback)on_send_signal_activate, app); - glade_xml_signal_connect_data (glade, "on_quit_activate", - (GCallback)on_quit_activate, app); + glade_xml_signal_connect_data (glade, "on_send_signal_activate", + (GCallback) on_send_signal_activate, app); + + glade_xml_signal_connect_data (glade, "on_quit_activate", + (GCallback) on_quit_activate, app); - glade_xml_signal_connect_data (glade, "on_about_activate", - (GCallback)on_about_activate, app); + glade_xml_signal_connect_data (glade, "on_about_activate", + (GCallback) on_about_activate, app); - glade_xml_signal_connect_data (glade, "on_window_destroy", - (GCallback)on_window_destroy, app); + glade_xml_signal_connect_data (glade, "on_window_destroy", + (GCallback) on_window_destroy, app); - glade_xml_signal_connect_data (glade, "on_popup_menu_show", - (GCallback)on_popup_menu_show, app); + glade_xml_signal_connect_data (glade, "on_popup_menu_show", + (GCallback) on_popup_menu_show, app); - glade_xml_signal_connect_data (glade, "on_show_decorations_toggle", - (GCallback)on_show_decorations_toggle, app); + glade_xml_signal_connect_data (glade, "on_show_decorations_toggle", + (GCallback) on_show_decorations_toggle, app); - glade_xml_signal_connect_data (glade, "on_delete_event_hide", - (GCallback)on_delete_event_hide, app); + glade_xml_signal_connect_data (glade, "on_delete_event_hide", + (GCallback) on_delete_event_hide, app); - glade_xml_signal_connect_data (glade, "on_select_device_activate", - (GCallback)on_select_device, app); + glade_xml_signal_connect_data (glade, "on_select_device_activate", + (GCallback) on_select_device, app); #if HAVE_GCONF - glade_xml_signal_connect_data (glade, "on_preferences_activate", - (GCallback)on_preferences_activate, app); + glade_xml_signal_connect_data (glade, "on_preferences_activate", + (GCallback) on_preferences_activate, app); - glade_xml_signal_connect_data (glade, "on_prefs_apply_clicked", - (GCallback)on_prefs_apply_clicked, app); + glade_xml_signal_connect_data (glade, "on_prefs_apply_clicked", + (GCallback) on_prefs_apply_clicked, app); - glade_xml_signal_connect_data (glade, "on_prefs_cancel_clicked", - (GCallback)on_prefs_cancel_clicked, app); + glade_xml_signal_connect_data (glade, "on_prefs_cancel_clicked", + (GCallback) on_prefs_cancel_clicked, app); #else gtk_widget_hide (glade_xml_get_widget (glade, "preferences")); @@ -102,14 +102,14 @@ fakeapp_new(void) app->winnest = glade_xml_get_widget (glade, "winnest"); - g_signal_connect(app->window, "key-press-event", - (GCallback)key_event, app); + g_signal_connect (app->window, "key-press-event", + (GCallback) key_event, app); - g_signal_connect(app->window, "key-release-event", - (GCallback)key_event, app); + g_signal_connect (app->window, "key-release-event", + (GCallback) key_event, app); app->prefs_window = glade_xml_get_widget (glade, "prefswindow"); - gtk_window_set_transient_for (GTK_WINDOW (app->prefs_window), + gtk_window_set_transient_for (GTK_WINDOW (app->prefs_window), GTK_WINDOW (app->window)); app->entry_display = glade_xml_get_widget (glade, "entry_display"); @@ -121,17 +121,17 @@ fakeapp_new(void) app->popupmenu = glade_xml_get_widget (glade, "popupmenu_menu"); app->about_window = glade_xml_get_widget (glade, "aboutwindow"); - gtk_window_set_transient_for (GTK_WINDOW (app->about_window), + gtk_window_set_transient_for (GTK_WINDOW (app->about_window), GTK_WINDOW (app->window)); - g_signal_connect_swapped (glade_xml_get_widget (glade, "button_about_close"), - "clicked", G_CALLBACK (gtk_widget_hide), - app->about_window); + g_signal_connect_swapped (glade_xml_get_widget + (glade, "button_about_close"), "clicked", + G_CALLBACK (gtk_widget_hide), app->about_window); return app; } void -fakeapp_create_gui(FakeApp *app) +fakeapp_create_gui (FakeApp * app) { GdkPixmap *back; GdkColor color; @@ -140,273 +140,319 @@ fakeapp_create_gui(FakeApp *app) /* Configure the main window title and size */ gtk_window_set_title (GTK_WINDOW (app->window), app->win_title); - gtk_widget_set_size_request(app->window, app->device_width, app->device_height); + gtk_widget_set_size_request (app->window, app->device_width, + app->device_height); /* Move and set the size of the window for the Xnest. */ - gtk_widget_set_size_request(app->winnest, - app->device_display_width, - app->device_display_height); - gtk_fixed_move (GTK_FIXED(app->fixed), app->winnest, - app->device_display_x, - app->device_display_y); + gtk_widget_set_size_request (app->winnest, + app->device_display_width, + app->device_display_height); + gtk_fixed_move (GTK_FIXED (app->fixed), app->winnest, + app->device_display_x, app->device_display_y); /* Force this widget to have X resources, so we can use it */ gtk_widget_realize (app->fixed); /* Set the device image, by setting the back buffer of the widget */ - back = gdk_pixmap_new (app->fixed->window, app->device_width, app->device_height, -1); + back = + gdk_pixmap_new (app->fixed->window, app->device_width, app->device_height, + -1); gc = gdk_gc_new (GDK_DRAWABLE (back)); gdk_color_parse ("black", &color); gdk_gc_set_rgb_fg_color (gc, &color); - gdk_draw_rectangle (GDK_DRAWABLE (back), gc, TRUE, 0, 0, app->device_width, app->device_height); - gdk_draw_pixbuf (GDK_DRAWABLE (back), NULL, app->device_img, 0, 0, 0, 0, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); + gdk_draw_rectangle (GDK_DRAWABLE (back), gc, TRUE, 0, 0, app->device_width, + app->device_height); + gdk_draw_pixbuf (GDK_DRAWABLE (back), NULL, app->device_img, 0, 0, 0, 0, -1, + -1, GDK_RGB_DITHER_NONE, 0, 0); gdk_window_set_back_pixmap (app->fixed->window, back, FALSE); g_object_unref (gc); /* Now setup the buttons */ - for (button = app->button_head; button; button=button->next) + for (button = app->button_head; button; button = button->next) { GtkWidget *eventbox; - button->normal_img = gdk_pixmap_new (app->fixed->window, button->width, button->height, -1); - gdk_draw_pixbuf (GDK_DRAWABLE (button->normal_img), NULL, app->device_img, button->x, button->y, 0, 0, button->width, button->height, GDK_RGB_DITHER_NONE, 0, 0); + button->normal_img = + gdk_pixmap_new (app->fixed->window, button->width, button->height, + -1); + gdk_draw_pixbuf (GDK_DRAWABLE (button->normal_img), NULL, + app->device_img, button->x, button->y, 0, 0, + button->width, button->height, GDK_RGB_DITHER_NONE, 0, + 0); button->image = gtk_image_new_from_pixmap (button->normal_img, NULL); gtk_widget_show (button->image); eventbox = gtk_event_box_new (); gtk_widget_show (eventbox); gtk_container_add (GTK_CONTAINER (eventbox), button->image); - g_signal_connect (eventbox, "button-press-event", G_CALLBACK(button_press), button); - g_signal_connect (eventbox, "button-release-event", G_CALLBACK(button_release), button); + g_signal_connect (eventbox, "button-press-event", + G_CALLBACK (button_press), button); + g_signal_connect (eventbox, "button-release-event", + G_CALLBACK (button_release), button); gtk_fixed_put (GTK_FIXED (app->fixed), eventbox, button->x, button->y); - - if (button->overlay) { - button->active_img = gdk_pixmap_new (app->fixed->window, button->width, button->height, -1); - g_assert (button->active_img); - gc = gdk_gc_new (GDK_DRAWABLE (button->active_img)); - gdk_draw_drawable (button->active_img, gc, button->normal_img, 0, 0, 0, 0, -1, -1); - gdk_draw_pixbuf (button->active_img, gc, button->overlay, 0, 0, 0, 0, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); - } else { - button->active_img = gdk_pixmap_new (app->fixed->window, button->width, button->height, -1); - gdk_draw_pixbuf (button->active_img, NULL, app->device_img, button->x, button->y, 0, 0, button->width, button->height, GDK_RGB_DITHER_NONE, 0, 0); - gc = gdk_gc_new (GDK_DRAWABLE (button->active_img)); - gdk_color_parse ("yellow", &color); - gdk_gc_set_rgb_fg_color (gc, &color); - gdk_draw_rectangle (GDK_DRAWABLE (button->active_img), gc, FALSE, 0, 0, button->width - 1, button->height - 1); - g_object_unref (gc); - } + + if (button->overlay) + { + button->active_img = + gdk_pixmap_new (app->fixed->window, button->width, button->height, + -1); + g_assert (button->active_img); + gc = gdk_gc_new (GDK_DRAWABLE (button->active_img)); + gdk_draw_drawable (button->active_img, gc, button->normal_img, 0, 0, + 0, 0, -1, -1); + gdk_draw_pixbuf (button->active_img, gc, button->overlay, 0, 0, 0, + 0, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); + } + else + { + button->active_img = + gdk_pixmap_new (app->fixed->window, button->width, button->height, + -1); + gdk_draw_pixbuf (button->active_img, NULL, app->device_img, + button->x, button->y, 0, 0, button->width, + button->height, GDK_RGB_DITHER_NONE, 0, 0); + gc = gdk_gc_new (GDK_DRAWABLE (button->active_img)); + gdk_color_parse ("yellow", &color); + gdk_gc_set_rgb_fg_color (gc, &color); + gdk_draw_rectangle (GDK_DRAWABLE (button->active_img), gc, FALSE, 0, + 0, button->width - 1, button->height - 1); + g_object_unref (gc); + } } gtk_widget_show (app->window); } static gboolean -key_event (GtkWidget *widget, GdkEventKey *event, FakeApp *app) +key_event (GtkWidget * widget, GdkEventKey * event, FakeApp * app) { - if (app->xnest_window == 0) { - g_warning("Skipping event send, no window to send to"); - } else { - XEvent xevent; - xevent.xkey.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease; - xevent.xkey.window = GDK_WINDOW_XWINDOW (app->winnest->window); - xevent.xkey.root = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (gdk_drawable_get_screen (app->winnest->window))); - xevent.xkey.time = event->time; - - /* FIXME, the following might cause problems for non-GTK apps */ - - xevent.xkey.x = 0; - xevent.xkey.y = 0; - xevent.xkey.x_root = 0; - xevent.xkey.y_root = 0; - xevent.xkey.state = event->state; - xevent.xkey.keycode = event->hardware_keycode; - xevent.xkey.same_screen = TRUE; - - gdk_error_trap_push (); - XSendEvent (GDK_WINDOW_XDISPLAY - (app->winnest->window), app->xnest_window, - False, NoEventMask, &xevent); - - gdk_display_sync (gtk_widget_get_display (widget)); - - if (gdk_error_trap_pop ()) { - g_warning("X error on XSendEvent"); + if (app->xnest_window == 0) + { + g_warning ("Skipping event send, no window to send to"); + } + else + { + XEvent xevent; + xevent.xkey.type = + (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease; + xevent.xkey.window = GDK_WINDOW_XWINDOW (app->winnest->window); + xevent.xkey.root = + GDK_WINDOW_XWINDOW (gdk_screen_get_root_window + (gdk_drawable_get_screen (app->winnest->window))); + xevent.xkey.time = event->time; + + /* FIXME, the following might cause problems for non-GTK apps */ + + xevent.xkey.x = 0; + xevent.xkey.y = 0; + xevent.xkey.x_root = 0; + xevent.xkey.y_root = 0; + xevent.xkey.state = event->state; + xevent.xkey.keycode = event->hardware_keycode; + xevent.xkey.same_screen = TRUE; + + gdk_error_trap_push (); + XSendEvent (GDK_WINDOW_XDISPLAY + (app->winnest->window), app->xnest_window, + False, NoEventMask, &xevent); + + gdk_display_sync (gtk_widget_get_display (widget)); + + if (gdk_error_trap_pop ()) + { + g_warning ("X error on XSendEvent"); + } } - } return TRUE; } gboolean -fakeapp_start_server(FakeApp *app) +fakeapp_start_server (FakeApp * app) { int pid; gchar winid[32]; gchar exec_buf[2048]; gchar **exec_vector = NULL; - g_snprintf(winid, 32, "%li", - gdk_x11_drawable_get_xid(app->winnest->window)); + g_snprintf (winid, 32, "%li", + gdk_x11_drawable_get_xid (app->winnest->window)); - g_snprintf(exec_buf, 2048, "%s %s %s -parent %s", - "Xnest", - app->xnest_dpy_name, - app->xnest_bin_options, - winid ); + g_snprintf (exec_buf, 2048, "%s %s %s -parent %s", + "Xnest", app->xnest_dpy_name, app->xnest_bin_options, winid); /* Split the above up into something execv can digest */ - exec_vector = g_strsplit(exec_buf, " ", 0); - - signal(SIGCHLD, fakeapp_catch_sigchild); - - pid = fork(); - switch (pid) { - case 0: - execv(app->xnest_bin_path, exec_vector); - g_warning( "Failed to Launch %s\n", app->xnest_bin_path); - exit(1); - case -1: - g_warning("Failed to Launch %s\n", app->xnest_bin_path); - break; - default: - g_strfreev(exec_vector); - app->xnest_pid = pid; - xnest_pid = pid; - } - - if (pid == -1 || !keys_init(app)) + exec_vector = g_strsplit (exec_buf, " ", 0); + + signal (SIGCHLD, fakeapp_catch_sigchild); + + pid = fork (); + switch (pid) + { + case 0: + execv (app->xnest_bin_path, exec_vector); + g_warning ("Failed to Launch %s\n", app->xnest_bin_path); + exit (1); + case -1: + g_warning ("Failed to Launch %s\n", app->xnest_bin_path); + break; + default: + g_strfreev (exec_vector); + app->xnest_pid = pid; + xnest_pid = pid; + } + + if (pid == -1 || !keys_init (app)) { g_warning ("'%s' Did not start correctly.", exec_buf); - g_warning ("Please restart with working --xnest-bin-options, --xnest-bin, options."); - exit(1); + g_warning + ("Please restart with working --xnest-bin-options, --xnest-bin, options."); + exit (1); } /* Disable the debug signal if we are not running Xephyr */ - if (strstr(app->xnest_bin_path, "Xephyr") == NULL) { - gtk_widget_set_sensitive (app->debug_menu, FALSE); - } else { - gtk_widget_set_sensitive (app->debug_menu, TRUE); - } + if (strstr (app->xnest_bin_path, "Xephyr") == NULL) + { + gtk_widget_set_sensitive (app->debug_menu, FALSE); + } + else + { + gtk_widget_set_sensitive (app->debug_menu, TRUE); + } if (app->start_cmd) { - pid = fork(); - switch (pid) { - case 0: - setenv("DISPLAY", app->xnest_dpy_name, 1); - execl("/bin/sh", "sh", "-c", app->start_cmd, 0); - g_warning( "Failed to Launch %s\n", app->start_cmd); - exit(1); - case -1: - g_warning("Failed to Launch %s\n", app->start_cmd); - break; - default: - break; - } - } - + pid = fork (); + switch (pid) + { + case 0: + setenv ("DISPLAY", app->xnest_dpy_name, 1); + execl ("/bin/sh", "sh", "-c", app->start_cmd, 0); + g_warning ("Failed to Launch %s\n", app->start_cmd); + exit (1); + case -1: + g_warning ("Failed to Launch %s\n", app->start_cmd); + break; + default: + break; + } + } + return FALSE; } static void -fakeapp_catch_sigchild(int sign) +fakeapp_catch_sigchild (int sign) { pid_t this_pid; - this_pid = waitpid(-1, 0, WNOHANG); - if (this_pid != xnest_pid) return; + this_pid = waitpid (-1, 0, WNOHANG); + if (this_pid != xnest_pid) + return; gtk_main_quit (); } gboolean -fakeapp_restart_server(FakeApp *app) +fakeapp_restart_server (FakeApp * app) { if (app->xnest_pid > 0) { - XCloseDisplay(app->xnest_dpy); + XCloseDisplay (app->xnest_dpy); - signal(SIGCHLD, SIG_DFL); /* start_server() will reset this */ + signal (SIGCHLD, SIG_DFL); /* start_server() will reset this */ kill (app->xnest_pid, SIGTERM); } - sleep(1); /* give server a chance to quit */ + sleep (1); /* give server a chance to quit */ - return fakeapp_start_server(app); + return fakeapp_start_server (app); } -void -usage(char *progname) +void +usage (char *progname) { - fprintf(stderr, - "%s " VERSION " usage:\n" - "--xnest-dpy, -xd Display String for Xnest to use. ( default ':1')\n" - "--xnest-bin, -xn Location of Xnest binary ( default " XNEST_BIN ")\n" - "--xnest-bin-options -xo Command line opts to pass to server ( Default '-ac' )\n" - "--title, -t Set the window title\n" - "--device, -d Device config file to use\n" - "--help, -h Show this help\n", - progname); - - exit(1); + fprintf (stderr, + "%s " VERSION " usage:\n" + "--xnest-dpy, -xd Display String for Xnest to use. ( default ':1')\n" + "--xnest-bin, -xn Location of Xnest binary ( default " + XNEST_BIN ")\n" + "--xnest-bin-options -xo Command line opts to pass to server ( Default '-ac' )\n" + "--title, -t Set the window title\n" + "--device, -d Device config file to use\n" + "--help, -h Show this help\n", progname); + + exit (1); } -int -main(int argc, char **argv) +int +main (int argc, char **argv) { FakeApp *app; - char *device = PKGDATADIR "/ipaq3800.xml"; - int i; - - gtk_init(&argc, &argv); + char *device = PKGDATADIR "/ipaq3800.xml"; + int i; + + gtk_init (&argc, &argv); /* TODO: use popt */ - app = fakeapp_new(); + app = fakeapp_new (); app->argv = argv; app->argc = argc; #ifdef HAVE_GCONF /* Do this here so that command line argument override the GConf prefs */ - gconf_prefs_init(app); + gconf_prefs_init (app); #endif - for (i = 1; i < argc; i++) { - if (!strcmp ("--xnest-dpy", argv[i]) || !strcmp ("-xd", argv[i])) { - if (++i>=argc) usage (argv[0]); - app->xnest_dpy_name = argv[i]; - continue; - } - if (!strcmp ("--xnest-bin", argv[i]) || !strcmp ("-xn", argv[i])) { - if (++i>=argc) usage (argv[0]); - app->xnest_bin_path = argv[i]; - continue; - } - if (!strcmp ("--xnest-bin-options", argv[i]) - || !strcmp ("-xo", argv[i])) { - if (++i>=argc) usage (argv[0]); - app->xnest_bin_options = argv[i]; - continue; - } - - if (!strcmp ("--device", argv[i]) || !strcmp ("-d", argv[i])) { - if (++i>=argc) usage (argv[0]); - device = argv[i]; - continue; - } - if (!strcmp ("--title", argv[i]) || !strcmp ("-t", argv[i])) { - if (++i>=argc) usage (argv[0]); - app->win_title = argv[i]; - continue; - } - - if (!strcmp("--help", argv[i]) || !strcmp("-h", argv[i])) { - usage(argv[0]); + for (i = 1; i < argc; i++) + { + if (!strcmp ("--xnest-dpy", argv[i]) || !strcmp ("-xd", argv[i])) + { + if (++i >= argc) + usage (argv[0]); + app->xnest_dpy_name = argv[i]; + continue; + } + if (!strcmp ("--xnest-bin", argv[i]) || !strcmp ("-xn", argv[i])) + { + if (++i >= argc) + usage (argv[0]); + app->xnest_bin_path = argv[i]; + continue; + } + if (!strcmp ("--xnest-bin-options", argv[i]) + || !strcmp ("-xo", argv[i])) + { + if (++i >= argc) + usage (argv[0]); + app->xnest_bin_options = argv[i]; + continue; + } + + if (!strcmp ("--device", argv[i]) || !strcmp ("-d", argv[i])) + { + if (++i >= argc) + usage (argv[0]); + device = argv[i]; + continue; + } + if (!strcmp ("--title", argv[i]) || !strcmp ("-t", argv[i])) + { + if (++i >= argc) + usage (argv[0]); + app->win_title = argv[i]; + continue; + } + + if (!strcmp ("--help", argv[i]) || !strcmp ("-h", argv[i])) + { + usage (argv[0]); + } + + usage (argv[0]); } - usage(argv[0]); - } - - config_init(app, device); + config_init (app, device); - fakeapp_create_gui(app); + fakeapp_create_gui (app); - g_idle_add ((GSourceFunc)fakeapp_start_server, app); - gtk_main(); + g_idle_add ((GSourceFunc) fakeapp_start_server, app); + gtk_main (); return 0; } diff --git a/src/prefs.c b/src/prefs.c index 7e723e7..a2f2411 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -20,48 +20,60 @@ #include #include "prefs.h" -gboolean fakeapp_restart_server(FakeApp *app); /* TODO: move to a header */ +gboolean fakeapp_restart_server (FakeApp * app); /* TODO: move to a header */ static GConfClient *gconf = NULL; -void gconf_prefs_init(FakeApp *app) { +void +gconf_prefs_init (FakeApp * app) +{ char *s; gconf = gconf_client_get_default (); g_return_if_fail (gconf != NULL); - + s = gconf_client_get_string (gconf, GCONF_DISPLAY, NULL); - if (s != NULL && *s != '\0') { - app->xnest_dpy_name = s; - } + if (s != NULL && *s != '\0') + { + app->xnest_dpy_name = s; + } s = gconf_client_get_string (gconf, GCONF_SERVER, NULL); - if (s != NULL && *s != '\0') { - app->xnest_bin_path = s; - } + if (s != NULL && *s != '\0') + { + app->xnest_bin_path = s; + } s = gconf_client_get_string (gconf, GCONF_SERVER_OPTIONS, NULL); - if (s != NULL && *s != '\0') { - app->xnest_bin_options = s; - } + if (s != NULL && *s != '\0') + { + app->xnest_bin_options = s; + } s = gconf_client_get_string (gconf, GCONF_START_CMD, NULL); - if (s != NULL && *s != '\0') { - app->start_cmd = s; - } + if (s != NULL && *s != '\0') + { + app->start_cmd = s; + } } -void on_preferences_activate (GtkMenuItem *menuitem, FakeApp *app) { +void +on_preferences_activate (GtkMenuItem * menuitem, FakeApp * app) +{ gtk_entry_set_text (GTK_ENTRY (app->entry_display), app->xnest_dpy_name); gtk_entry_set_text (GTK_ENTRY (app->entry_server), app->xnest_bin_path); - gtk_entry_set_text (GTK_ENTRY (app->entry_options), app->xnest_bin_options ? app->xnest_bin_options : ""); + gtk_entry_set_text (GTK_ENTRY (app->entry_options), + app->xnest_bin_options ? app->xnest_bin_options : ""); - gtk_entry_set_text (GTK_ENTRY (app->entry_start), app->start_cmd ? app->start_cmd : ""); + gtk_entry_set_text (GTK_ENTRY (app->entry_start), + app->start_cmd ? app->start_cmd : ""); gtk_window_present (GTK_WINDOW (app->prefs_window)); } -void on_prefs_apply_clicked (GtkWidget *widget, FakeApp *app) { +void +on_prefs_apply_clicked (GtkWidget * widget, FakeApp * app) +{ const char *s = NULL; s = gtk_entry_get_text (GTK_ENTRY (app->entry_display)); @@ -82,6 +94,8 @@ void on_prefs_apply_clicked (GtkWidget *widget, FakeApp *app) { gtk_widget_hide (app->prefs_window); } -void on_prefs_cancel_clicked (GtkWidget *widget, FakeApp *app) { +void +on_prefs_cancel_clicked (GtkWidget * widget, FakeApp * app) +{ gtk_widget_hide (app->prefs_window); } diff --git a/src/prefs.h b/src/prefs.h index 3c30f88..ae79442 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -6,8 +6,14 @@ #define GCONF_SERVER_OPTIONS "/apps/Xoo/xserver-options" #define GCONF_START_CMD "/apps/Xoo/startup-command" -void gconf_prefs_init(FakeApp *app); +void +gconf_prefs_init (FakeApp * app); -void on_preferences_activate (GtkMenuItem *menuitem, FakeApp *app); -void on_prefs_apply_clicked (GtkWidget *widget, FakeApp *app); -void on_prefs_cancel_clicked (GtkWidget *widget, FakeApp *app); +void +on_preferences_activate (GtkMenuItem * menuitem, FakeApp * app); + +void +on_prefs_apply_clicked (GtkWidget * widget, FakeApp * app); + +void +on_prefs_cancel_clicked (GtkWidget * widget, FakeApp * app); -- cgit v1.2.3