workspace support (attached)



Hi,

this is a patch that enables workspace (aka virtual desktop) support
for hamster via wnck (1).
It patches https://bugzilla.gnome.org/show_bug.cgi?id=529401

The patch only changes applet.py, the preferences would probably have
to be patched as well .. I assume not everyone prefers this behaviour.

Let me know what you think =)

Cheers, Ludwig

1)
http://library.gnome.org/devel/libwnck/stable/index.html
diff --git a/hamster/applet.py b/hamster/applet.py
index 7f694a1..80b38b7 100755
--- a/hamster/applet.py
+++ b/hamster/applet.py
@@ -44,6 +44,8 @@ import idle
 
 import pango
 
+import wnck
+
 try:
     import pynotify
     PYNOTIFY = True
@@ -290,12 +292,17 @@ class HamsterApplet(object):
         self.notify_on_idle = conf.get("notify_on_idle")
         runtime.dispatcher.add_handler('conf_changed', self.on_conf_changed)
 
-
         # init nagging timeout
         if PYNOTIFY:
             self.notify = Notifier(self.button)
             self.on_conf_changed(None, ("notify_interval", conf.get("notify_interval")))
 
+        # init desktop switching
+        self.screen = wnck.screen_get_default()
+        self.screen.connect("active-workspace-changed", self.on_workspace_changed)
+        self.active_workspace = None
+        self.workspace_activities = dict()
+
 
     """UI functions"""
     def refresh_hamster(self):
@@ -580,6 +587,41 @@ class HamsterApplet(object):
             runtime.storage.touch_fact(self.last_activity,
                                        end_time = self.dbusIdleListener.getIdleFrom())
 
+    def on_workspace_changed(self, screen, old_workspace):
+        # take note of current activity, set new activity depending on workspace
+        new_workspace = self.screen.get_active_workspace()
+        now = dt.datetime.now()
+        
+        if old_workspace is None:
+            # this happens once at startup
+            self.active_workspace = new_workspace
+            return True
+
+        logging.debug("changing from workspace %s to %s" % \
+                (self.active_workspace.get_name(), new_workspace.get_name()))
+        
+        # always take note of current activity on active workspace
+        current_activity = self.last_activity
+        self.workspace_activities[self.active_workspace] = current_activity
+        logging.debug("setting activity on workspace %s to %s" % (self.active_workspace.get_name(), current_activity['name']))
+        
+        # set activity to last activity on new workspace
+        if new_workspace in self.workspace_activities.keys():
+            new_activity = self.workspace_activities[new_workspace]
+            logging.debug("last activity on workspace was %s", (new_activity['name']),)
+            self.current_activity = new_activity
+            if new_activity is not current_activity:
+                logging.debug("setting current activity to %s" % (new_activity['name']),)
+                runtime.storage.update_fact(
+                        new_activity['id'], new_activity['name'],
+                        new_activity['description'], now, None)
+
+        # change active workspace
+        self.active_workspace = new_workspace
+        
+        return True
+
+
     """global shortcuts"""
     def on_keybinding_activated(self, event, data):
         self.__show_toggle(None, not self.button.get_active())

Attachment: signature.asc
Description: Digital signature



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