Permalink
Browse files

upgrade to xpybutil2

  • Loading branch information...
1 parent df8f4e4 commit d99db69c4097e7828262246270979274c025d2b3 @BurntSushi committed Feb 20, 2012
Showing with 49 additions and 86 deletions.
  1. +0 −5 pager-multihead
  2. +13 −17 pagermh/client.py
  3. +4 −7 pagermh/pager.py
  4. +8 −12 pagermh/prompt.py
  5. +24 −45 pagermh/state.py
View
@@ -1,14 +1,9 @@
#!/usr/bin/env python2
-import sys
-
import pygtk
pygtk.require('2.0')
import gtk
-from xpybutil import conn, root
-import xpybutil.ewmh as ewmh
-
import pagermh.state as state
import pagermh.pager as pager
import pagermh.client as client
View
@@ -1,17 +1,16 @@
-import sys
-
import gtk
import xcb
-from xpybutil import conn, root
import xpybutil.ewmh as ewmh
+import xpybutil.rect as rect
import xpybutil.util as util
+import xpybutil.window as window
import state
import pager
def update_tracking_clients():
- clist = ewmh.get_client_list(conn, root).reply()
+ clist = ewmh.get_client_list().reply()
for c in clist:
if c not in state.clients:
track_client(c)
@@ -22,9 +21,9 @@ def update_tracking_clients():
def track_client(c):
assert c not in state.clients
- wstate = ewmh.get_wm_state(conn, c).reply()
+ wstate = ewmh.get_wm_state(c).reply()
for atom in wstate:
- aname = util.get_atom_name(conn, atom)
+ aname = util.get_atom_name(atom)
# For now, while I decide how to handle these guys
if aname == '_NET_WM_STATE_STICKY':
@@ -51,9 +50,9 @@ def __init__(self, wid):
self.wid = wid
self.gdk = gtk.gdk.window_foreign_new_for_display(state.gtk_display,
self.wid)
- self.name = ewmh.get_wm_name(conn, self.wid).reply()
+ self.name = ewmh.get_wm_name(self.wid).reply()
self.geom = self.get_geometry()
- self.desk = ewmh.get_wm_desktop(conn, self.wid).reply()
+ self.desk = ewmh.get_wm_desktop(self.wid).reply()
self.invis = gtk.Invisible()
self.gdk.set_events(gtk.gdk.PROPERTY_CHANGE_MASK
@@ -63,7 +62,7 @@ def __init__(self, wid):
# This is interesting; look for configure events on the decor window
if state.wmname.lower() == 'openbox':
- pid = util.get_parent_window(conn, self.wid)
+ pid = util.get_parent_window(self.wid)
pgdk = gtk.gdk.window_foreign_new_for_display(state.gtk_display,
pid)
pinvis = gtk.Invisible()
@@ -78,19 +77,16 @@ def __init__(self, wid):
def update_state(self):
self.hidden = False
- hatom = util.get_atom(conn, '_NET_WM_STATE_HIDDEN')
- states = ewmh.get_wm_state(conn, self.wid).reply()
+ hatom = util.get_atom('_NET_WM_STATE_HIDDEN')
+ states = ewmh.get_wm_state(self.wid).reply()
if states is not None and hatom in states:
self.hidden = True
def get_monitor_area(self):
- return state.get_monitor_area(self.geom)
+ return rect.get_monitor_area(self.geom, state.monitors)
def get_geometry(self):
- geom = conn.core.GetGeometry(util.get_parent_window(conn,
- self.wid)).reply()
-
- return geom.x, geom.y, geom.width, geom.height
+ return window.get_geometry(self.wid)
def remove(self):
pager.update(self.desk)
@@ -106,7 +102,7 @@ def cb_configure(self, widget, event):
def cb_prop_change(self, widget, e):
try:
if e.atom == '_NET_WM_DESKTOP':
- newd = ewmh.get_wm_desktop(conn, self.wid).reply()
+ newd = ewmh.get_wm_desktop(self.wid).reply()
if newd is not None and newd != self.desk:
oldd = self.desk
self.desk = newd
View
@@ -1,12 +1,10 @@
-import sys
-
import gtk
-from xpybutil import conn, root
import xpybutil.ewmh as ewmh
+import xpybutil.rect as rect
import config
-from keymousebind import keybinds, desktop_clicked
+from keymousebind import desktop_clicked
import state
desktops = []
@@ -63,7 +61,7 @@ def init():
# This does not allow for between-monitor struts... For another day!
if config.struts:
wx, wy, ww, wh = config.x, config.y, config.width, config.height
- mx, my, mw, mh = state.get_monitor_area((wx, wy, ww, wh))
+ mx, my, mw, mh = rect.get_monitor_area((wx, wy, ww, wh), state.monitors)
rw, rh = state.root_geom['width'], state.root_geom['height']
struts = { nm: 0 for nm in
@@ -93,8 +91,7 @@ def init():
struts['bottom_start_x'] = wx
struts['bottom_end_x'] = wx + ww
- ewmh.set_wm_strut_partial_checked(conn, _window.window.xid,
- **struts).check()
+ ewmh.set_wm_strut_partial_checked(_window.window.xid, **struts).check()
def update_desktop_order():
if not state.visibles:
View
@@ -1,10 +1,6 @@
-import sys
-
-import gobject
import gtk
import pango
-from xpybutil import conn, root
import xpybutil.ewmh as ewmh
import xpybutil.icccm as icccm
@@ -20,8 +16,8 @@
def desktops(result_fun, prefix_complete=True, homogenous=True):
global currentPrompt
- desks = range(0, ewmh.get_number_of_desktops(conn, root).reply())
- names = ewmh.get_desktop_names(conn, root).reply()
+ desks = range(0, ewmh.get_number_of_desktops().reply())
+ names = ewmh.get_desktop_names().reply()
lst = []
for d in desks:
nm = names[d] if d < len(names) else d
@@ -34,8 +30,8 @@ def windows(result_fun, prefix_complete=False, homogenous=False,
current_desk=False):
global currentPrompt
- desks = range(0, ewmh.get_number_of_desktops(conn, root).reply())
- names = ewmh.get_desktop_names(conn, root).reply()
+ desks = range(0, ewmh.get_number_of_desktops().reply())
+ names = ewmh.get_desktop_names().reply()
content = {}
for d in desks:
@@ -48,15 +44,15 @@ def windows(result_fun, prefix_complete=False, homogenous=False,
content[name] = []
- clients = ewmh.get_client_list_stacking(conn, root).reply()
+ clients = ewmh.get_client_list_stacking().reply()
for c in reversed(clients):
- nm = ewmh.get_wm_desktop(conn, c).reply()
+ nm = ewmh.get_wm_desktop(c).reply()
if nm < len(names):
nm = names[nm]
if nm in content:
- wm_name = ewmh.get_wm_name(conn, c).reply()
+ wm_name = ewmh.get_wm_name(c).reply()
if not wm_name:
- wm_name = icccm.get_wm_name(conn, c).reply()
+ wm_name = icccm.get_wm_name(c).reply()
if not wm_name or not isinstance(wm_name, basestring):
wm_name = 'N/A'
content[nm].append((wm_name, c))
View
@@ -4,17 +4,17 @@
import gtk
import keybinder
-from xpybutil import conn, root
+import xpybutil
import xpybutil.ewmh as ewmh
wmrunning = False
while not wmrunning:
- w = ewmh.get_supporting_wm_check(conn, root).reply()
+ w = ewmh.get_supporting_wm_check(xpybutil.root).reply()
if w:
- childw = ewmh.get_supporting_wm_check(conn, w).reply()
+ childw = ewmh.get_supporting_wm_check(w).reply()
if childw == w:
wmrunning = True
- wmname = ewmh.get_wm_name(conn, childw).reply()
+ wmname = ewmh.get_wm_name(childw).reply()
print '%s window manager is running...' % wmname
sys.stdout.flush()
@@ -26,7 +26,7 @@
import config
from keymousebind import keybinds
-xinerama = conn(xcb.xinerama.key)
+xinerama = xpybutil.conn(xcb.xinerama.key)
gtk_display = gtk.gdk.display_get_default()
gtk_screen = gtk_display.get_default_screen()
@@ -38,11 +38,11 @@
# Initial setup
if config.desktops:
- ewmh.set_desktop_names_checked(conn, root, config.desktops).check()
- ewmh.set_desktop_layout_checked(conn, root, ewmh.Orientation.Horz,
+ ewmh.set_desktop_names_checked(config.desktops).check()
+ ewmh.set_desktop_layout_checked(ewmh.Orientation.Horz,
len(config.desktops), 1,
ewmh.StartingCorner.TopLeft).check()
- ewmh.request_number_of_desktops_checked(conn, len(config.desktops)).check()
+ ewmh.request_number_of_desktops_checked(len(config.desktops)).check()
# Is this a horizontal or vertical pager?
if config.width > config.height:
@@ -58,14 +58,14 @@
print >> sys.stderr, 'could not bind %s' % key_string
# Start loading information
-desk_num = ewmh.get_number_of_desktops(conn, root).reply()
-desk_names = ewmh.get_desktop_names(conn, root).reply()
-root_geom = ewmh.get_desktop_geometry(conn, root).reply()
+desk_num = ewmh.get_number_of_desktops().reply()
+desk_names = ewmh.get_desktop_names().reply()
+root_geom = ewmh.get_desktop_geometry().reply()
-activewin = ewmh.get_active_window(conn, root).reply()
-desktop = ewmh.get_current_desktop(conn, root).reply()
-stacking = ewmh.get_client_list_stacking(conn, root).reply()
-visibles = ewmh.get_visible_desktops(conn, root).reply()
+activewin = ewmh.get_active_window().reply()
+desktop = ewmh.get_current_desktop().reply()
+stacking = ewmh.get_client_list_stacking().reply()
+visibles = ewmh.get_visible_desktops().reply()
clients = {}
monitors = []
@@ -77,27 +77,6 @@ def get_desk_name(i):
else:
return str(i)
-def rect_intersect_area(r1, r2):
- x1, y1, w1, h1 = r1
- x2, y2, w2, h2 = r2
- if x2 < x1 + w1 and x2 + w2 > x1 and y2 < y1 + h1 and y2 + h2 > y1:
- iw = min(x1 + w1 - 1, x2 + w2 - 1) - max(x1, x2) + 1
- ih = min(y1 + h1 - 1, y2 + h2 - 1) - max(y1, y2) + 1
- return iw * ih
-
- return 0
-
-def get_monitor_area(search):
- marea = 0
- mon = None
- for mx, my, mw, mh in monitors:
- a = rect_intersect_area((mx, my, mw, mh), search)
- if a > marea:
- marea = a
- mon = (mx, my, mw, mh)
-
- return mon
-
def update_monitor_area():
global monitors, xtophys
@@ -115,26 +94,26 @@ def cb_prop_change(widget, e):
global activewin, desk_names, desk_num, desktop, stacking, visibles
if e.atom == '_NET_DESKTOP_GEOMETRY':
- root_geom = ewmh.get_desktop_geometry(conn, root).reply()
+ root_geom = ewmh.get_desktop_geometry().reply()
update_monitor_area()
elif e.atom == '_NET_ACTIVE_WINDOW':
- activewin = ewmh.get_active_window(conn, root).reply()
+ activewin = ewmh.get_active_window().reply()
elif e.atom == '_NET_CURRENT_DESKTOP':
- desktop = ewmh.get_current_desktop(conn, root).reply()
+ desktop = ewmh.get_current_desktop().reply()
elif e.atom == '_NET_CLIENT_LIST_STACKING':
- stacking = ewmh.get_client_list_stacking(conn, root).reply()
+ stacking = ewmh.get_client_list_stacking().reply()
elif e.atom == '_NET_VISIBLE_DESKTOPS':
- visibles = ewmh.get_visible_desktops(conn, root).reply()
+ visibles = ewmh.get_visible_desktops().reply()
elif e.atom in ('_NET_DESKTOP_NAMES', '_NET_NUMBER_OF_DESKTOPS'):
- desk_num = ewmh.get_number_of_desktops(conn, root).reply()
- desk_names = ewmh.get_desktop_names(conn, root).reply()
+ desk_num = ewmh.get_number_of_desktops().reply()
+ desk_names = ewmh.get_desktop_names().reply()
# This works around what I think is weird behavior in Openbox.
# Sometimes Openbox will "fix" the desktop names... please don't!
if len(desk_names) > desk_num:
names = desk_names[0:desk_num]
- ewmh.set_desktop_names_checked(conn, root, names).check()
- desk_names = ewmh.get_desktop_names(conn, root).reply()
+ ewmh.set_desktop_names_checked(names).check()
+ desk_names = ewmh.get_desktop_names().reply()
update_monitor_area()

0 comments on commit d99db69

Please sign in to comment.