Mercurial > emacs
diff src/gtkutil.c @ 106186:9b6f45dd8386
Use a select wrapper around the GLib event loop, thus taking into account GLib
timeouts and event sources. This simplifies Gtk+-code a lot, and is needed
for handling GConf death/restart.
* xterm.c: #include xgselect.h.
(x_initialize): Call xgselect_initialize.
* xsettings.c (something_changedCB): C++ comments => C comments.
(init_gconf): Do not deal with any GLib file descriptors, xg_select
does that now.
* gtkutil.c (xg_timer, xg_process_timeouts, xg_start_timer)
(xg_stop_timer, menu_grab_callback_cnt, menu_grab_callback)
(scroll_bar_button_cb): Remove.
(create_menus): C++ comments => C comments. Don't bind grab-notify
event.
(xg_create_scroll_bar): Don't bind button-press-event and
button-release-event.
* process.c: Include xgselect.h if defined (USE_GTK) ||
defined (HAVE_GCONF).
(wait_reading_process_output): Call xg_select for the same condition.
* xgselect.c (xg_select): New function to better integrate with
GLib/Gtk event handling. Needed if GConf daemon dies/restarts.
* xgselect.h: New file, declare xg_select, xgselect_initialize.
* Makefile.in (XOBJ): Add xgselect.o.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Sat, 21 Nov 2009 15:28:59 +0000 |
parents | 0ea716305b13 |
children | 471e6932ea09 |
line wrap: on
line diff
--- a/src/gtkutil.c Sat Nov 21 11:52:23 2009 +0000 +++ b/src/gtkutil.c Sat Nov 21 15:28:59 2009 +0000 @@ -29,7 +29,6 @@ #include "blockinput.h" #include "syssignal.h" #include "window.h" -#include "atimer.h" #include "gtkutil.h" #include "termhooks.h" #include "keyboard.h" @@ -181,11 +180,6 @@ /*********************************************************************** Utility functions ***********************************************************************/ -/* The timer for scroll bar repetition and menu bar timeouts. - NULL if no timer is started. */ -static struct atimer *xg_timer; - - /* The next two variables and functions are taken from lwlib. */ static widget_value *widget_value_free_list; static int malloc_cpt; @@ -426,58 +420,6 @@ gdk_window_set_cursor (GDK_WINDOW (children->data), cursor); } -/* Timer function called when a timeout occurs for xg_timer. - This function processes all GTK events in a recursive event loop. - This is done because GTK timer events are not seen by Emacs event - detection, Emacs only looks for X events. When a scroll bar has the - pointer (detected by button press/release events below) an Emacs - timer is started, and this function can then check if the GTK timer - has expired by calling the GTK event loop. - Also, when a menu is active, it has a small timeout before it - pops down the sub menu under it. */ - -static void -xg_process_timeouts (timer) - struct atimer *timer; -{ - BLOCK_INPUT; - /* Ideally we would like to just handle timer events, like the Xt version - of this does in xterm.c, but there is no such feature in GTK. */ - while (gtk_events_pending ()) - gtk_main_iteration (); - UNBLOCK_INPUT; -} - -/* Start the xg_timer with an interval of 0.1 seconds, if not already started. - xg_process_timeouts is called when the timer expires. The timer - started is continuous, i.e. runs until xg_stop_timer is called. */ - -static void -xg_start_timer () -{ - if (! xg_timer) - { - EMACS_TIME interval; - EMACS_SET_SECS_USECS (interval, 0, 100000); - xg_timer = start_atimer (ATIMER_CONTINUOUS, - interval, - xg_process_timeouts, - 0); - } -} - -/* Stop the xg_timer if started. */ - -static void -xg_stop_timer () -{ - if (xg_timer) - { - cancel_atimer (xg_timer); - xg_timer = 0; - } -} - /* Insert NODE into linked LIST. */ static void @@ -1895,29 +1837,6 @@ unref_cl_data ((xg_menu_cb_data*) client_data); } -/* Callback called when a menu does a grab or ungrab. That means the - menu has been activated or deactivated. - Used to start a timer so the small timeout the menus in GTK uses before - popping down a menu is seen by Emacs (see xg_process_timeouts above). - W is the widget that does the grab (not used). - UNGRAB_P is TRUE if this is an ungrab, FALSE if it is a grab. - CLIENT_DATA is NULL (not used). */ - -/* Keep track of total number of grabs. */ -static int menu_grab_callback_cnt; - -static void -menu_grab_callback (GtkWidget *widget, - gboolean ungrab_p, - gpointer client_data) -{ - if (ungrab_p) menu_grab_callback_cnt--; - else menu_grab_callback_cnt++; - - if (menu_grab_callback_cnt > 0 && ! xg_timer) xg_start_timer (); - else if (menu_grab_callback_cnt == 0 && xg_timer) xg_stop_timer (); -} - /* Make a GTK widget that contains both UTF8_LABEL and UTF8_KEY (both must be non-NULL) and can be inserted into a menu item. @@ -2232,10 +2151,10 @@ else { wmenu = gtk_menu_bar_new (); - // Set width of menu bar to a small value so it doesn't enlarge - // a small initial frame size. The width will be set to the - // width of the frame later on when it is added to a container. - // height -1: Natural height. + /* Set width of menu bar to a small value so it doesn't enlarge + a small initial frame size. The width will be set to the + width of the frame later on when it is added to a container. + height -1: Natural height. */ gtk_widget_set_size_request (wmenu, 1, -1); } @@ -2251,9 +2170,6 @@ if (deactivate_cb) g_signal_connect (G_OBJECT (wmenu), "selection-done", deactivate_cb, 0); - - g_signal_connect (G_OBJECT (wmenu), - "grab-notify", G_CALLBACK (menu_grab_callback), 0); } if (! menu_bar_p && add_tearoff_p) @@ -3177,34 +3093,6 @@ xg_remove_widget_from_map (id); } -/* Callback for button press/release events. Used to start timer so that - the scroll bar repetition timer in GTK gets handled. - Also, sets bar->dragging to Qnil when dragging (button release) is done. - WIDGET is the scroll bar widget the event is for (not used). - EVENT contains the event. - USER_DATA points to the struct scrollbar structure. - - Returns FALSE to tell GTK that it shall continue propagate the event - to widgets. */ - -static gboolean -scroll_bar_button_cb (widget, event, user_data) - GtkWidget *widget; - GdkEventButton *event; - gpointer user_data; -{ - if (event->type == GDK_BUTTON_PRESS && ! xg_timer) - xg_start_timer (); - else if (event->type == GDK_BUTTON_RELEASE) - { - struct scroll_bar *bar = (struct scroll_bar *) user_data; - if (xg_timer) xg_stop_timer (); - bar->dragging = Qnil; - } - - return FALSE; -} - /* Create a scroll bar widget for frame F. Store the scroll bar in BAR. SCROLL_CALLBACK is the callback to invoke when the value of the @@ -3246,17 +3134,6 @@ G_CALLBACK (xg_gtk_scroll_destroy), (gpointer) (EMACS_INT) scroll_id); - /* Connect to button press and button release to detect if any scroll bar - has the pointer. */ - g_signal_connect (G_OBJECT (wscroll), - "button-press-event", - G_CALLBACK (scroll_bar_button_cb), - (gpointer) bar); - g_signal_connect (G_OBJECT (wscroll), - "button-release-event", - G_CALLBACK (scroll_bar_button_cb), - (gpointer) bar); - /* The scroll bar widget does not draw on a window of its own. Instead it draws on the parent window, in this case the edit widget. So whenever the edit widget is cleared, the scroll bar needs to redraw