feature request and patch



I have recently switched from KDE to Gnome, and found myself missing a
particular feature.

In KDE you can use the Mouse Wheel on the desktop to switch
workspaces. I found this extraordinarily convenient.

I went ahead and implemented this is Nautilus and attached the
patch. It currently is always on; I haven't implemented a feature for
it yet.

I was wondering if this is a feature other may want, and thus justify
merging it into trunk?


--
Casey
--- nautilus-desktop-window.c	2003-10-01 01:56:19.000000000 -0500
+++ nautilus-desktop-window.c-2	2004-05-17 16:12:44.000000000 -0500
@@ -38,16 +38,89 @@
 
 #define STATUS_BAR_PATH         "/status"
 #define MENU_BAR_PATH           "/menu"
 
 struct NautilusDesktopWindowDetails {
 	int dummy;
 };
 
+
+static int getScreenCount() {
+  Atom as = XInternAtom (gdk_display, "_NET_NUMBER_OF_DESKTOPS", FALSE);
+  int count = 0;
+  gulong nitems;
+  gulong bytes_after;
+  gulong *num;
+  int format;
+  Atom type = None;
+  XGetWindowProperty (gdk_display,
+                      RootWindow (gdk_display, DefaultScreen(gdk_display)),
+                      as,
+                      0, G_MAXLONG,
+                      False, XA_CARDINAL, &type, &format, &nitems,
+                      &bytes_after, (guchar **)&num);
+  count = *num;
+  XFree (num);
+  return count;
+}
+
+static int getCurrentScreen() {
+  Atom mt = XInternAtom (gdk_display, "_NET_CURRENT_DESKTOP", FALSE);
+  int currentScreen = 0;
+  gulong nitems;
+  gulong bytes_after;
+  gulong *num;
+  int format;
+  Atom type = None;
+  XGetWindowProperty (gdk_display,
+                      RootWindow (gdk_display, DefaultScreen(gdk_display)),
+                      mt,
+                      0, G_MAXLONG,
+                      False, XA_CARDINAL, &type, &format, &nitems,
+                      &bytes_after, (guchar **)&num);
+  currentScreen = *num;
+  XFree (num);
+  return currentScreen;
+}
+
+static gboolean CASEYscrolled( GtkWidget *widget, GdkEvent *event) {
+  // g_print ("mouse clicked [%d]\n", event->scroll.direction);
+
+  int i = event->scroll.direction == 0 ? -1 : 1;
+  int next=getCurrentScreen() + i;
+  if (next < 0 ) {
+    next  = getScreenCount() -1;
+  } else if (next >= getScreenCount()) {
+    next = 0;
+  }
+
+  XEvent xev;
+
+  xev.xclient.type = ClientMessage;
+  xev.xclient.serial = 0;
+  xev.xclient.send_event = True;
+  xev.xclient.display = gdk_display;
+  xev.xclient.window = RootWindow (gdk_display, DefaultScreen(gdk_display));
+  xev.xclient.message_type = XInternAtom (gdk_display, "_NET_CURRENT_DESKTOP", FALSE);
+  xev.xclient.format = 32;
+  xev.xclient.data.l[0] = next;
+  xev.xclient.data.l[1] = 0;
+  xev.xclient.data.l[2] = 0;
+
+  XSendEvent (gdk_display,
+              RootWindow (gdk_display, DefaultScreen(gdk_display)),
+              False,
+	      SubstructureRedirectMask | SubstructureNotifyMask,
+	      &xev);
+
+  return FALSE;
+}
+
+
 static void set_wmspec_desktop_hint (GdkWindow *window);
 
 GNOME_CLASS_BOILERPLATE (NautilusDesktopWindow, nautilus_desktop_window,
 			 NautilusSpatialWindow, NAUTILUS_TYPE_SPATIAL_WINDOW)
 
 static void
 nautilus_desktop_window_instance_init (NautilusDesktopWindow *window)
 {
@@ -335,16 +408,23 @@
 
 	/* This is the new way to set up the desktop window */
 	set_wmspec_desktop_hint (widget->window);
 
 	set_desktop_window_id (window, widget->window);
 
 	g_signal_connect (gtk_window_get_screen (GTK_WINDOW (window)), "size_changed",
 			  G_CALLBACK (nautilus_desktop_window_screen_size_changed), window);
+
+	g_signal_connect ( widget, "scroll_event", (GtkSignalFunc)CASEYscrolled, NULL);
+
+	gtk_widget_set_events (widget,
+			       gtk_widget_get_events(widget) |
+			       GDK_SCROLL_MASK);
+
 }
 
 static void
 real_add_current_location_to_history_list (NautilusWindow *window)
 {
 	/* Do nothing. The desktop window's location should not
 	 * show up in the history list.
 	 */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]