Skip to content

Commit

Permalink
Revert "Use .to_atoms() and .to_strings()"
Browse files Browse the repository at this point in the history
After some discussion, this seems to break several things (likely a bug in
xcffib, not this commit in particular). We'll un-revert this when we fix
whatever is causing problems in xcffib.

This reverts commit bae4b9e.
  • Loading branch information
tych0 committed Oct 31, 2014
1 parent 969cfa4 commit 1739627
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
13 changes: 7 additions & 6 deletions libqtile/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def setOpacity(self, opacity):

def getOpacity(self):
opacity = self.window.get_property(
"_NET_WM_WINDOW_OPACITY", unpack=int
"_NET_WM_WINDOW_OPACITY", unpack="I"
)
if not opacity:
return 1.0
Expand Down Expand Up @@ -655,11 +655,11 @@ def handle_ConfigureRequest(self, e):
def update_strut(self):
strut = self.window.get_property(
"_NET_WM_STRUT_PARTIAL",
unpack=int
unpack="I" * 12
)
strut = strut or self.window.get_property(
"_NET_WM_STRUT",
unpack=int
unpack="I" * 4
)
strut = strut or (0, 0, 0, 0)
self.qtile.update_gaps(strut, self.strut)
Expand Down Expand Up @@ -1028,9 +1028,10 @@ def update_wm_net_icon(self):
Set a dict with the icons of the window
"""

icon = self.window.get_property('_NET_WM_ICON', 'CARDINAL', unpack=int)
if not icon:
ret = self.window.get_property('_NET_WM_ICON', 'CARDINAL')
if not ret:
return
icon = list(map(ord, ret.value))

icons = {}
while True:
Expand Down Expand Up @@ -1071,7 +1072,7 @@ def handle_ClientMessage(self, event):
prev_state = self.window.get_property(
'_NET_WM_STATE',
'ATOM',
unpack=int
unpack='I'
)
if not prev_state:
prev_state = []
Expand Down
36 changes: 17 additions & 19 deletions libqtile/xcbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import print_function, division

import six
import struct

from xcffib.xproto import CW, WindowClass, EventMask
from xcffib.xfixes import SelectionEventMask
Expand Down Expand Up @@ -435,7 +436,8 @@ def get_name(self):
def get_wm_hints(self):
r = self.get_property("WM_HINTS", xcffib.xproto.GetPropertyType.Any)
if r:
l = r.value.to_atoms()
data = struct.pack("c" * len(r.value), *(list(r.value)))
l = struct.unpack_from("=IIIIIIIII", data)
flags = set()
for k, v in HintsFlags.items():
if l[0] & v:
Expand All @@ -458,7 +460,8 @@ def get_wm_normal_hints(self):
xcffib.xproto.GetPropertyType.Any
)
if r:
l = r.value.to_atoms()
data = struct.pack("c" * len(r.value), *(list(r.value)))
l = struct.unpack_from("=IIIIIIIIIIIIII", data)
flags = set()
for k, v in NormalHintsFlags.items():
if l[0] & v:
Expand All @@ -481,15 +484,16 @@ def get_wm_normal_hints(self):
def get_wm_protocols(self):
r = self.get_property("WM_PROTOCOLS", xcffib.xproto.GetPropertyType.Any)
if r:
l = r.value.to_atoms()
data = struct.pack("c" * len(r.value), *(list(r.value)))
l = struct.unpack_from("=" + "L" * r.value_len, data)
return set([self.conn.atoms.get_name(i) for i in l])
else:
return set()

def get_wm_state(self):
r = self.get_property("WM_STATE", xcffib.xproto.GetPropertyType.Any)
if r:
return r.value.to_atoms()
return struct.unpack('=LL', ''.encode().join(r.value))

def get_wm_class(self):
"""
Expand Down Expand Up @@ -525,7 +529,7 @@ def get_geometry(self):
return q.reply()

def get_wm_desktop(self):
r = self.get_property("_NET_WM_DESKTOP", "CARDINAL", unpack=int)
r = self.get_property("_NET_WM_DESKTOP", "CARDINAL", unpack='I')

if r:
return r[0]
Expand All @@ -534,7 +538,7 @@ def get_wm_type(self):
"""
http://standards.freedesktop.org/wm-spec/wm-spec-latest.html#id2551529
"""
r = self.get_property('_NET_WM_WINDOW_TYPE', "ATOM", unpack=int)
r = self.get_property('_NET_WM_WINDOW_TYPE', "ATOM", unpack='I')
if r:
name = self.conn.atoms.get_name(r[0])
return WindowTypes.get(name, name)
Expand All @@ -544,13 +548,13 @@ def get_net_wm_state(self):
# We're returning only the first one, but we don't need anything
# other than _NET_WM_STATE_FULLSCREEN (at least for now)
# Fixing this requires refactoring each call to use a list instead
r = self.get_property('_NET_WM_STATE', "ATOM", unpack=int)
r = self.get_property('_NET_WM_STATE', "ATOM", unpack='I')
if r:
name = self.conn.atoms.get_name(r[0])
return WindowStates.get(name, name)

def get_net_wm_pid(self):
r = self.get_property("_NET_WM_PID", unpack=int)
r = self.get_property("_NET_WM_PID", unpack="I")
if r:
return r[0]

Expand Down Expand Up @@ -619,9 +623,9 @@ def set_property(self, name, value, type=None, format=None):

def get_property(self, prop, type=None, unpack=None):
"""
Return the contents of a property as a GetPropertyReply. If unpack
is specified, a tuple of values is returned. The type to unpack,
either `str` or `int` must be specified.
Return the contents of a property as a GetPropertyReply, or
a tuple of values if unpack is specified, which is a format
string to be used with the struct module.
"""
if type is None:
if prop not in PropertyMap:
Expand All @@ -643,15 +647,9 @@ def get_property(self, prop, type=None, unpack=None):
).reply()

if not r.value_len:
if unpack:
return []
return None
elif unpack:
# Should we allow more options for unpacking?
if unpack is int:
return r.value.to_atoms()
elif unpack is str:
return r.value.to_string()
elif unpack is not None:
return struct.unpack_from(unpack, r.value.buf())
else:
return r
except xcffib.xproto.WindowError:
Expand Down

0 comments on commit 1739627

Please sign in to comment.