[mousetweaks] Use a common X Display accessor
- From: Gerd Kohlberger <gerdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetweaks] Use a common X Display accessor
- Date: Sun, 10 Oct 2010 13:27:08 +0000 (UTC)
commit 6f669c7f6e8219f79e505856d2392fc7fc3e7473
Author: Gerd Kohlberger <gerdk src gnome org>
Date: Sun Oct 10 15:26:41 2010 +0200
Use a common X Display accessor
src/mt-common.c | 8 ++++++--
src/mt-common.h | 6 +++++-
src/mt-cursor-manager.c | 24 +++++++++---------------
src/mt-listener.c | 21 +++++++++------------
src/mt-main.c | 14 +++++---------
5 files changed, 34 insertions(+), 39 deletions(-)
---
diff --git a/src/mt-common.c b/src/mt-common.c
index 69efdcd..b8b6482 100644
--- a/src/mt-common.c
+++ b/src/mt-common.c
@@ -17,10 +17,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <gtk/gtk.h>
-
#include "mt-common.h"
+Display *
+mt_common_get_xdisplay (void)
+{
+ return GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+}
+
void
mt_common_show_help (GdkScreen *screen, guint32 timestamp)
{
diff --git a/src/mt-common.h b/src/mt-common.h
index c752250..d8e8b9d 100644
--- a/src/mt-common.h
+++ b/src/mt-common.h
@@ -25,7 +25,8 @@
#endif
#include <glib/gi18n.h>
-#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
G_BEGIN_DECLS
@@ -85,8 +86,11 @@ typedef enum
MT_MESSAGE_LOGOUT
} MtMessageType;
+Display * mt_common_get_xdisplay (void);
+
void mt_common_show_help (GdkScreen *screen,
guint32 timestamp);
+
gint mt_common_show_dialog (const gchar *primary,
const gchar *secondary,
MtMessageType type);
diff --git a/src/mt-cursor-manager.c b/src/mt-cursor-manager.c
index 03f204d..a2fe8c4 100644
--- a/src/mt-cursor-manager.c
+++ b/src/mt-cursor-manager.c
@@ -17,13 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
#include <X11/Xcursor/Xcursor.h>
#include <X11/extensions/Xfixes.h>
-#include "mt-cursor.h"
#include "mt-cursor-manager.h"
+#include "mt-cursor.h"
+#include "mt-common.h"
static int xfixes_event = 0;
static int xfixes_error = 0;
@@ -51,16 +50,11 @@ static GdkFilterReturn mt_cursor_manager_event_filter (GdkXEvent *gdk_xeve
G_DEFINE_TYPE (MtCursorManager, mt_cursor_manager, G_TYPE_OBJECT)
-static Display *
-mt_cursor_manager_display (void)
-{
- return GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
-}
-
static void
mt_cursor_manager_init (MtCursorManager *manager)
{
GtkSettings *gs;
+ Display *dpy;
manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
MT_TYPE_CURSOR_MANAGER,
@@ -71,12 +65,12 @@ mt_cursor_manager_init (MtCursorManager *manager)
g_free,
g_object_unref);
+ dpy = mt_common_get_xdisplay ();
+
/* init XFixes extension */
- if (XFixesQueryExtension (mt_cursor_manager_display (),
- &xfixes_event, &xfixes_error))
+ if (XFixesQueryExtension (dpy, &xfixes_event, &xfixes_error))
{
- XFixesSelectCursorInput (mt_cursor_manager_display (),
- GDK_ROOT_WINDOW (),
+ XFixesSelectCursorInput (dpy, GDK_ROOT_WINDOW (),
XFixesDisplayCursorNotifyMask);
}
@@ -137,7 +131,7 @@ mt_cursor_manager_set_xcursor (MtCursor *cursor)
gushort width, height;
gushort xhot, yhot;
- dpy = mt_cursor_manager_display ();
+ dpy = mt_common_get_xdisplay ();
mt_cursor_get_dimension (cursor, &width, &height);
ximage = XcursorImageCreate (width, height);
xcursor = 0;
@@ -268,7 +262,7 @@ mt_cursor_manager_current_cursor (MtCursorManager *manager)
g_return_val_if_fail (MT_IS_CURSOR_MANAGER (manager), NULL);
- image = XFixesGetCursorImage (mt_cursor_manager_display ());
+ image = XFixesGetCursorImage (mt_common_get_xdisplay ());
cursor = NULL;
if (image->name && image->name[0] != '\0')
diff --git a/src/mt-listener.c b/src/mt-listener.c
index af30b80..7bbbf0e 100644
--- a/src/mt-listener.c
+++ b/src/mt-listener.c
@@ -17,9 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <gdk/gdkx.h>
-
#include "mt-listener.h"
+#include "mt-common.h"
#define XBUTTON_MASK (Button1Mask | Button2Mask | Button3Mask | \
Button4Mask | Button5Mask)
@@ -157,12 +156,6 @@ mt_listener_emit_motion_event (MtListener *listener,
g_signal_emit (listener, signals[MOTION_EVENT], 0, &ev);
}
-static Display *
-mt_listener_display (void)
-{
- return GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
-}
-
static gboolean
mt_listener_maybe_emit (MtListener *listener, guint mask)
{
@@ -254,7 +247,7 @@ mt_listener_mouse_moved (MtListener *listener)
gint x, y, win_x_return, win_y_return;
guint mask_return;
- dpy = mt_listener_display ();
+ dpy = mt_common_get_xdisplay ();
gdk_error_trap_push ();
XQueryPointer (dpy, DefaultRootWindow (dpy),
@@ -301,11 +294,13 @@ mt_listener_mouse_idle (gpointer data)
static void
mt_listener_grab_buttons (void)
{
- Display *dpy = mt_listener_display ();
+ Display *dpy;
+
+ dpy = mt_common_get_xdisplay ();
gdk_error_trap_push ();
XGrabButton (dpy, AnyButton, AnyModifier,
- gdk_x11_get_default_root_xwindow (),
+ XDefaultRootWindow (dpy),
True, ButtonPressMask | ButtonReleaseMask,
GrabModeSync, GrabModeAsync, None, None);
XSync (dpy, False);
@@ -315,7 +310,9 @@ mt_listener_grab_buttons (void)
static void
mt_listener_ungrab_buttons (void)
{
- Display *dpy = mt_listener_display ();
+ Display *dpy;
+
+ dpy = mt_common_get_xdisplay ();
gdk_error_trap_push ();
XUngrabButton (dpy, AnyButton, AnyModifier, XDefaultRootWindow (dpy));
diff --git a/src/mt-main.c b/src/mt-main.c
index 1f18af7..339007e 100644
--- a/src/mt-main.c
+++ b/src/mt-main.c
@@ -61,12 +61,6 @@ typedef struct _MtCliArgs
gboolean login;
} MtCliArgs;
-static Display *
-mt_main_display (void)
-{
- return GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
-}
-
static GdkScreen *
mt_main_current_screen (MtData *mt)
{
@@ -111,7 +105,7 @@ mt_main_generate_button_event (MtData *mt,
{
Display *dpy;
- dpy = mt_main_display ();
+ dpy = mt_common_get_xdisplay ();
button = mt_main_check_mouse_orientation (mt, button);
gdk_error_trap_push ();
@@ -692,12 +686,14 @@ get_gconf_options (MtData *mt)
static MtData *
mt_data_init (void)
{
+ Display *dpy;
MtData *mt;
gint nil;
mt = g_slice_new0 (MtData);
+ dpy = mt_common_get_xdisplay ();
- if (!XTestQueryExtension (mt_main_display (), &nil, &nil, &nil, &nil))
+ if (!XTestQueryExtension (dpy, &nil, &nil, &nil, &nil))
{
g_slice_free (MtData, mt);
g_critical ("No XTest extension found. Aborting.");
@@ -705,7 +701,7 @@ mt_data_init (void)
}
/* continue sending event requests inspite of other grabs */
- XTestGrabControl (mt_main_display (), True);
+ XTestGrabControl (dpy, True);
mt->client = gconf_client_get_default ();
gconf_client_add_dir (mt->client, GNOME_MOUSE_DIR,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]