Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #/home/macbuntu/bin/sync-workspaces.py
- # Released under a GPLv3 Licence by Clockwork PC 2011
- # www.clockworkpc.com.au
- # You are entitled to the following four freedoms:
- # Freedom 0: To run this program for any purpose
- # Freedom 1: To study how this program works and change it to make it do what you wish
- # Freedom 2: To redistribute copies so you can help your neighbour
- # Freedom 3: To distribute copies of your modified version to others
- import os
- numWorkspaces = raw_input("""How many workspaces do you want?
- """)
- print ""
- print "You have chosen to use " + numWorkspaces + " workspaces. Well done."
- os.system("gconftool-2 -s /apps/metacity/general/num_workspaces --type int " + numWorkspaces)
- import math
- from gi.repository import GObject
- from gi.repository import GConf
- from gi.repository import Gtk
- from gi.repository import Wnck
- class WorkspaceSyncer:
- WORKSPACES_KEY = '/apps/metacity/general/num_workspaces'
- def __init__(self):
- # The screen must be gotten before entering the main loop.
- # The pager must be in the widget hierarchy to make changes.
- self.screen = Wnck.Screen.get_default()
- self.pager = Wnck.Pager()
- self.window = Gtk.Window()
- self.window.add(self.pager)
- def get_workspace_count(self):
- """Return the number of workspaces."""
- settings = GConf.Client.get_default()
- workspace_count = self.screen.get_workspace_count()
- if workspace_count < 4:
- # Unity expects 4 workspaces.
- print "Setting number of workspaces to 4."
- settings.set_int(self.WORKSPACES_KEY, 4)
- workspace_count = 4
- elif workspace_count > 20:
- # Metacity supports up to 20 workspaces.
- print "Setting number of workspaces to 20."
- settings.set_int(self.WORKSPACES_KEY, 20)
- workspace_count = 20
- return workspace_count
- def get_rows_and_columns(self, workspace_count):
- base = math.sqrt(workspace_count)
- rows = int(base)
- if base % 1 == 0.0:
- cols = rows
- else:
- cols = rows + 1
- return rows, cols
- def sync(self):
- wm_name = self.screen.get_window_manager_name()
- if wm_name != 'Metacity':
- print "Metacity is not running. No actions take."
- else:
- workspace_count = self.get_workspace_count()
- rows, cols = self.get_rows_and_columns(workspace_count)
- success = self.pager.set_n_rows(rows)
- if success:
- print "Workspace layout set to %sx%s" % (rows, cols)
- desktopSize = "%sx%s" % (rows, cols)
- print desktopSize
- os.system("xcowsay 'Your desktop size is now '" + desktopSize)
- Gtk.main_quit()
- def start(self):
- GObject.idle_add(self.sync)
- Gtk.main()
- if __name__ == "__main__":
- syncer = WorkspaceSyncer()
- syncer.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement