Advertisement
clockworkpc

Multiple Workspace in Ubunt Unity 2D

Jan 4th, 2012
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.95 KB | None | 0 0
  1. #!/usr/bin/python
  2. #/home/macbuntu/bin/sync-workspaces.py
  3.  
  4. # Released under a GPLv3 Licence by Clockwork PC 2011
  5. # www.clockworkpc.com.au
  6.  
  7. # You are entitled to the following four freedoms:
  8. # Freedom 0: To run this program for any purpose
  9. # Freedom 1: To study how this program works and change it to make it do what you wish
  10. # Freedom 2: To redistribute copies so you can help your neighbour
  11. # Freedom 3: To distribute copies of your modified version to others
  12.  
  13. import os
  14.  
  15. numWorkspaces = raw_input("""How many workspaces do you want?
  16.  
  17. """)
  18.  
  19. print ""
  20. print "You have chosen to use " + numWorkspaces + " workspaces.  Well done."
  21.  
  22. os.system("gconftool-2 -s /apps/metacity/general/num_workspaces --type int " + numWorkspaces)
  23.  
  24. import math
  25.  
  26. from gi.repository import GObject
  27. from gi.repository import GConf
  28. from gi.repository import Gtk
  29. from gi.repository import Wnck
  30.  
  31.  
  32. class WorkspaceSyncer:
  33.  
  34.     WORKSPACES_KEY = '/apps/metacity/general/num_workspaces'
  35.  
  36.     def __init__(self):
  37.         # The screen must be gotten before entering the main loop.
  38.         # The pager must be in the widget hierarchy to make changes.
  39.         self.screen = Wnck.Screen.get_default()
  40.         self.pager = Wnck.Pager()
  41.         self.window = Gtk.Window()
  42.         self.window.add(self.pager)
  43.  
  44.     def get_workspace_count(self):
  45.         """Return the number of workspaces."""
  46.         settings = GConf.Client.get_default()
  47.         workspace_count = self.screen.get_workspace_count()
  48.         if workspace_count < 4:
  49.             # Unity expects 4 workspaces.
  50.             print "Setting number of workspaces to 4."
  51.             settings.set_int(self.WORKSPACES_KEY, 4)
  52.             workspace_count = 4
  53.         elif workspace_count > 20:
  54.             # Metacity supports up to 20 workspaces.
  55.             print "Setting number of workspaces to 20."
  56.             settings.set_int(self.WORKSPACES_KEY, 20)
  57.             workspace_count = 20
  58.         return workspace_count
  59.  
  60.     def get_rows_and_columns(self, workspace_count):
  61.         base = math.sqrt(workspace_count)
  62.         rows = int(base)
  63.         if base % 1 == 0.0:
  64.             cols = rows
  65.         else:
  66.             cols = rows + 1
  67.         return rows, cols
  68.  
  69.     def sync(self):
  70.         wm_name = self.screen.get_window_manager_name()
  71.         if wm_name != 'Metacity':
  72.             print "Metacity is not running. No actions take."
  73.         else:
  74.             workspace_count = self.get_workspace_count()
  75.             rows, cols = self.get_rows_and_columns(workspace_count)
  76.             success = self.pager.set_n_rows(rows)
  77.             if success:
  78.                 print "Workspace layout set to %sx%s" % (rows, cols)
  79.         desktopSize = "%sx%s" % (rows, cols)
  80.         print desktopSize
  81.         os.system("xcowsay 'Your desktop size is now '" + desktopSize)
  82.         Gtk.main_quit()
  83.  
  84.     def start(self):
  85.         GObject.idle_add(self.sync)
  86.         Gtk.main()
  87.  
  88.  
  89. if __name__ == "__main__":
  90.     syncer = WorkspaceSyncer()
  91.     syncer.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement