Handle video key

This commit is contained in:
Soren Sandmann Pedersen 2008-03-02 22:21:35 +00:00
parent 08ee65418e
commit 2946d2f3dc
2 changed files with 123 additions and 43 deletions

View File

@ -1,6 +1,6 @@
diff -up gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-randr-12 gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c diff -up gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-randr-12 gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c
--- gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-randr-12 2007-12-24 06:18:48.000000000 -0500 --- gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-randr-12 2007-12-24 06:18:48.000000000 -0500
+++ gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c 2008-02-12 14:42:57.000000000 -0500 +++ gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c 2008-03-02 17:26:08.000000000 -0500
@@ -36,6 +36,10 @@ @@ -36,6 +36,10 @@
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -12,7 +12,23 @@ diff -up gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-r
#ifdef HAVE_RANDR #ifdef HAVE_RANDR
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#endif #endif
@@ -61,258 +65,60 @@ G_DEFINE_TYPE (GsdXrandrManager, gsd_xra @@ -44,9 +48,14 @@
#define GSD_XRANDR_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_XRANDR_MANAGER, GsdXrandrManagerPrivate))
+#define VIDEO_KEYSYM "XF86Display"
+
struct GsdXrandrManagerPrivate
{
- gboolean dummy;
+ /* Key code of the fn-F7 video key (XF86Display) */
+ guint keycode;
+ RWScreen *rw_screen;
+ gboolean running;
};
enum {
@@ -61,248 +70,74 @@ G_DEFINE_TYPE (GsdXrandrManager, gsd_xra
static gpointer manager_object = NULL; static gpointer manager_object = NULL;
@ -38,8 +54,12 @@ diff -up gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-r
- g_error_free (error); - g_error_free (error);
- -
- return 0; - return 0;
-} +static GdkAtom
- +gnome_randr_atom (void)
+{
+ return gdk_atom_intern ("_GNOME_RANDR_ATOM", FALSE);
}
-static int -static int
-get_resolution (GConfClient *client, -get_resolution (GConfClient *client,
- int screen, - int screen,
@ -67,11 +87,30 @@ diff -up gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-r
- if (val == NULL) { - if (val == NULL) {
- return -1; - return -1;
- } - }
- +static Atom
+gnome_randr_xatom (void)
+{
+ return gdk_x11_atom_to_xatom (gnome_randr_atom());
+}
- if (sscanf (val, "%dx%d", &w, &h) != 2) { - if (sscanf (val, "%dx%d", &w, &h) != 2) {
- g_free (val); - g_free (val);
- return -1; - return -1;
- } +static GdkFilterReturn
+on_client_message (GdkXEvent *xevent,
+ GdkEvent *event,
+ gpointer data)
+{
+ RWScreen *screen = data;
+ XEvent *ev = (XEvent *)xevent;
+
+ if (ev->type == ClientMessage &&
+ ev->xclient.message_type == gnome_randr_xatom()) {
+
+ configuration_apply_stored (screen);
+
+ return GDK_FILTER_REMOVE;
}
- -
- g_free (val); - g_free (val);
- -
@ -79,18 +118,19 @@ diff -up gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-r
- *height = h; - *height = h;
- -
- return i; - return i;
+static GdkAtom +
+gnome_randr_atom (void) + /* Pass the event on to GTK+ */
+{ + return GDK_FILTER_CONTINUE;
+ return gdk_atom_intern ("_GNOME_RANDR_ATOM", FALSE);
} }
-static int -static int
-get_rate (GConfClient *client, -get_rate (GConfClient *client,
- char *display, - char *display,
- int screen) - int screen)
+static Atom +static GdkFilterReturn
+gnome_randr_xatom (void) +event_filter (GdkXEvent *xevent,
+ GdkEvent *event,
+ gpointer data)
{ {
- char *key; - char *key;
- int val; - int val;
@ -100,16 +140,22 @@ diff -up gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-r
- error = NULL; - error = NULL;
- val = gconf_client_get_int (client, key, &error); - val = gconf_client_get_int (client, key, &error);
- g_free (key); - g_free (key);
- + GsdXrandrManager *manager = data;
+ XEvent *xev = (XEvent *) xevent;
- if (error == NULL) { - if (error == NULL) {
- return val; - return val;
- } - }
- + if (!manager->priv->running)
+ return GDK_FILTER_CONTINUE;
- g_error_free (error); - g_error_free (error);
- -
- return 0; - return 0;
+ return gdk_x11_atom_to_xatom (gnome_randr_atom()); -}
} + /* verify we have a key event */
+ if (xev->xany.type != KeyPress && xev->xany.type != KeyRelease)
+ return GDK_FILTER_CONTINUE;
-static int -static int
-find_closest_size (XRRScreenSize *sizes, -find_closest_size (XRRScreenSize *sizes,
@ -133,25 +179,16 @@ diff -up gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-r
- closest_width = sizes[i].width; - closest_width = sizes[i].width;
- closest_height = sizes[i].height; - closest_height = sizes[i].height;
- } - }
+static GdkFilterReturn + if (xev->xkey.keycode == manager->priv->keycode) {
+on_client_message (GdkXEvent *xevent, + /* FIXME: here we should cycle between valid
+ GdkEvent *event, + * configurations, and save them
+ gpointer data) + */
+{ + configuration_apply_stored (manager->priv->rw_screen);
+ RWScreen *screen = data;
+ XEvent *ev = (XEvent *)xevent;
+ +
+ if (ev->type == ClientMessage && + return GDK_FILTER_CONTINUE;
+ ev->xclient.message_type == gnome_randr_xatom()) {
+
+ configuration_apply_stored (screen);
+
+ return GDK_FILTER_REMOVE;
} }
-
- return closest; - return closest;
+
+ /* Pass the event on to GTK+ */
+ return GDK_FILTER_CONTINUE; + return GDK_FILTER_CONTINUE;
} }
-#endif /* HAVE_RANDR */ -#endif /* HAVE_RANDR */
@ -193,10 +230,12 @@ diff -up gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-r
- || XRRQueryVersion (xdisplay, &major, &minor) == 0) { - || XRRQueryVersion (xdisplay, &major, &minor) == 0) {
- return; - return;
- } - }
- + GsdXrandrManager *manager = data;
- if (major != 1 || minor < 1) { - if (major != 1 || minor < 1) {
- g_message ("Display has unsupported version of XRandR (%d.%d), not setting resolution.", major, minor); - g_message ("Display has unsupported version of XRandR (%d.%d), not setting resolution.", major, minor);
- return; + if (!manager->priv->running)
return;
- } - }
- -
- client = gconf_client_get_default (); - client = gconf_client_get_default ();
@ -283,27 +322,65 @@ diff -up gnome-settings-daemon-2.21.91/plugins/xrandr/gsd-xrandr-manager.c.add-r
- } - }
- -
-#endif /* HAVE_RANDR */ -#endif /* HAVE_RANDR */
+
+ /* FIXME: Set up any new screens here */ + /* FIXME: Set up any new screens here */
} }
gboolean gboolean
gsd_xrandr_manager_start (GsdXrandrManager *manager, @@ -311,8 +146,25 @@ gsd_xrandr_manager_start (GsdXrandrManag
GError **error)
{ {
+ RWScreen *rw_screen;
+
g_debug ("Starting xrandr manager"); g_debug ("Starting xrandr manager");
+
+ rw_screen = rw_screen_new (gdk_screen_get_default(), on_randr_event, NULL);
- apply_settings (manager); - apply_settings (manager);
- -
+ configuration_apply_stored (rw_screen); + manager->priv->running = TRUE;
+
+ if (manager->priv->keycode) {
+ XGrabKey (gdk_x11_get_default_xdisplay(),
+ manager->priv->keycode, AnyModifier,
+ gdk_x11_get_default_root_xwindow(),
+ True, GrabModeAsync, GrabModeAsync);
+ }
+
+ configuration_apply_stored (manager->priv->rw_screen);
+
+ gdk_window_add_filter (gdk_get_default_root_window(),
+ (GdkFilterFunc)event_filter,
+ manager);
+ +
+ gdk_add_client_message_filter (gnome_randr_atom(), + gdk_add_client_message_filter (gnome_randr_atom(),
+ on_client_message, + on_client_message,
+ rw_screen); + manager->priv->rw_screen);
+ +
return TRUE; return TRUE;
} }
@@ -320,6 +172,12 @@ void
gsd_xrandr_manager_stop (GsdXrandrManager *manager)
{
g_debug ("Stopping xrandr manager");
+
+ manager->priv->running = FALSE;
+
+ XUngrabKey (gdk_x11_get_default_xdisplay(),
+ manager->priv->keycode, AnyModifier,
+ gdk_x11_get_default_root_xwindow());
}
static void
@@ -400,8 +258,15 @@ gsd_xrandr_manager_class_init (GsdXrandr
static void
gsd_xrandr_manager_init (GsdXrandrManager *manager)
{
+ Display *dpy = gdk_x11_get_default_xdisplay ();
+ guint keyval = gdk_keyval_from_name (VIDEO_KEYSYM);
+ guint keycode = XKeysymToKeycode (dpy, keyval);
+
manager->priv = GSD_XRANDR_MANAGER_GET_PRIVATE (manager);
+ manager->priv->keycode = keycode;
+ manager->priv->rw_screen = rw_screen_new (
+ gdk_screen_get_default(), on_randr_event, NULL);
}
static void

View File

@ -1,6 +1,6 @@
Name: gnome-settings-daemon Name: gnome-settings-daemon
Version: 2.21.92 Version: 2.21.92
Release: 1%{?dist} Release: 2%{?dist}
Summary: The daemon sharing settings from GNOME to GTK+/KDE applications Summary: The daemon sharing settings from GNOME to GTK+/KDE applications
Group: System Environment/Daemons Group: System Environment/Daemons
@ -123,6 +123,9 @@ fi
%{_libdir}/pkgconfig/gnome-settings-daemon.pc %{_libdir}/pkgconfig/gnome-settings-daemon.pc
%changelog %changelog
* Sun Mar 2 2008 Soren Sandmann <sandmann@redhat.com> - 2.21.92-2
- Update randr patch to handle video key
* Fri Feb 29 2008 Jon McCann <jmccann@redhat.com> - 2.21.92-1 * Fri Feb 29 2008 Jon McCann <jmccann@redhat.com> - 2.21.92-1
- Update to 2.21.92 - Update to 2.21.92