Skip to content

Commit

Permalink
#1086 fix display modes info, use hex printout for icc data
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@13818 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Sep 22, 2016
1 parent 2faf64f commit 44e95af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
47 changes: 22 additions & 25 deletions src/xpra/platform/darwin/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def tomodelstr(v):
return MODELS.get(v, "unknown")
defs = (
("name", "CGColorSpaceCopyName", str),
("profile", "CGColorSpaceCopyICCProfile", str),
("icc-profile", "CGColorSpaceCopyICCProfile", str),
("icc-data", "CGColorSpaceCopyICCData", str),
("components", "CGColorSpaceGetNumberOfComponents", int),
("supports-output", "CGColorSpaceSupportsOutput", bool),
Expand All @@ -204,30 +204,18 @@ def tomodelstr(v):

def get_display_mode_info(mode):
defs = (
("width", "width", int),
("height", "height", int),
("pixel-encoding", "pixelEncoding", str),
("vrefresh", "refreshRate", int),
("io-flags", "ioFlags", int),
("id", "ioDisplayModeID", int),
("width", "CGDisplayModeGetWidth", int),
("height", "CGDisplayModeGetHeight", int),
("pixel-encoding", "CGDisplayModeCopyPixelEncoding", str),
("vrefresh", "CGDisplayModeGetRefreshRate", int),
("io-flags", "CGDisplayModeGetIOFlags", int),
("id", "CGDisplayModeGetIODisplayModeID", int),
("usable-for-desktop", "CGDisplayModeIsUsableForDesktopGUI", bool),
)
return _get_CG_conv(defs, mode)
return _call_CG_conv(defs, mode)

def get_display_modes_info(modes):
return tuple(get_display_mode_info(mode) for mode in modes)

def _get_CG_conv(obj, defs):
#utility for getting attributes on an object,
#then convert the return value using another function
#missing attributes are ignored, and None values are skipped
info = {}
for prop_name, attr_name, conv in defs:
v = getattr(obj, attr_name, None)
if v is not None:
info[prop_name] = conv(v)
else:
log("%s is not set or does not exist", attr_name)
return info
return dict((i,get_display_mode_info(mode)) for i,mode in enumerate(modes))


def _call_CG_conv(defs, argument):
Expand All @@ -239,7 +227,11 @@ def _call_CG_conv(defs, argument):
for prop_name, fn_name, conv in defs:
fn = getattr(CG, fn_name, None)
if fn:
v = fn(argument)
try:
v = fn(argument)
except Exception as e:
log("function %s failed: %s", fn_name, e)
continue
if v is not None:
info[prop_name] = conv(v)
else:
Expand Down Expand Up @@ -278,9 +270,14 @@ def recttotuple(r):
("colorspace", "CGDisplayCopyColorSpace", get_colorspace_info),
("opengl-acceleration", "CGDisplayUsesOpenGLAcceleration", bool),
("mode", "CGDisplayCopyDisplayMode", get_display_mode_info),
("modes", "CGDisplayCopyAllDisplayModes", get_display_modes_info),
)
return _call_CG_conv(defs, did)
info = _call_CG_conv(defs, did)
try:
modes = CG.CGDisplayCopyAllDisplayModes(did, None)
info["modes"] = get_display_modes_info(modes)
except:
log("failed to query display modes: %s", e)
return info

def get_displays_info():
from Quartz import CoreGraphics as CG #@UnresolvedImport
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/platform/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def main():
except:
pass #maybe running on OSX? hope for the best..
i = get_info()
print_nested_dict(i)
print_nested_dict(i, hex_keys=("data", "icc-data", "icc-profile"))


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions src/xpra/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def convert(text):
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', bytestostr(key)) ]
return sorted(l, key = alphanum_key)

def print_nested_dict(d, prefix="", lchar="*", pad=32, vformat=None, print_fn=None):
def print_nested_dict(d, prefix="", lchar="*", pad=32, vformat=None, print_fn=None, version_keys=("version", "revision"), hex_keys=("data", )):
#"smart" value formatting function:
def sprint(arg):
if print_fn:
Expand All @@ -654,9 +654,9 @@ def vf(k, v):
if vformat:
return nonl(vformat(v))
try:
if k.find("version")>=0 or k.find("revision")>=0:
if any(k.find(x)>=0 for x in version_keys):
return nonl(pver(v)).lstrip("v")
elif k=="data":
elif any(k.find(x)>=0 for x in hex_keys):
return binascii.hexlify(v)
except:
pass
Expand All @@ -675,7 +675,7 @@ def vf(k, v):
pass
else:
sprint("%s%s %s" % (prefix, lchar, k))
print_nested_dict(v, prefix+" ", "-", print_fn=print_fn)
print_nested_dict(v, prefix+" ", "-", print_fn=print_fn, version_keys=version_keys, hex_keys=hex_keys)
else:
sprint("%s%s %s : %s" % (prefix, lchar, str(k).ljust(l), vf(k, v)))

Expand Down

0 comments on commit 44e95af

Please sign in to comment.