Top

xpybutil.motif module

Implements a subset of the Motif spec. This module exists because some window managers still use this as the only way of toggling window decorations via events.

"""
Implements a subset of the Motif spec. This module exists 
because some window managers still use this as the only way of
toggling window decorations via events.
"""
import struct

import xcb.xproto

from xpybutil import conn as c
import util

__atoms = ['_MOTIF_WM_HINTS']

class Hint:
    Functions = 1 << 0
    Decorations = 1 << 1
    InputMode = 1 << 2
    Status = 1 << 3

class Function:
    _None = 0
    All = 1 << 0
    Resize = 1 << 1
    Move = 1 << 2
    Minimize = 1 << 3
    Maximize = 1 << 4
    Close = 1 << 5

class Decoration:
    _None = 0
    All = 1 << 0
    Border = 1 << 1
    ResizeH = 1 << 2
    Title = 1 << 3
    Menu = 1 << 4
    Minimize = 1 << 5
    Maximize = 1 << 6

class Input:
    Modeless = 0
    PrimaryApplicationModal = 1
    SystemModal = 2
    FullApplicationModal = 3

class Status:
    TearoffWindow = 1 << 0

# Some aliases
atom = util.get_atom
preplace = xcb.xproto.PropMode.Replace

# Build the atom cache for quicker access
util.build_atom_cache(__atoms)

# _MOTIF_WM_HINTS

class MotifHintsCookie(util.PropertyCookie):
    def reply(self):
        v = util.PropertyCookie.reply(self)

        if not v:
            return None

        return {
            'flags': {
                'Functions': v[0] & Hint.Functions > 0,
                'Decorations': v[0] & Hint.Decorations > 0,
                'InputMode': v[0] & Hint.InputMode > 0,
                'Status': v[0] & Hint.Status > 0
            },
            'function': v[1],
            'decoration': v[2],
            'input': v[3],
            'status': v[4]
        }

def get_hints(window):
    return MotifHintsCookie(util.get_property(window, '_MOTIF_WM_HINTS'))

def get_hints_unchecked(window):
    cook = util.get_property_unchecked(window, '_MOTIF_WM_HINTS')
    return MotifHintsCookie(cook)

def _pack_hints(flags, function, decoration, input, status):
    hints = [0] * 5

    if flags & Hint.Functions:
        hints[1] = function

    if flags & Hint.Decorations:
        hints[2] = decoration

    if flags & Hint.InputMode:
        hints[3] = input

    if flags & Hint.Status:
        hints[4] = status

    hints[0] = flags

    return struct.pack('I' * 5, *hints)

def set_hints(window, flags, function=Function._None,
              decoration=Decoration._None, input=Input.Modeless,
              status=Status.TearoffWindow):
    packed = _pack_hints(flags, function, decoration, input, status)
    return c.core.ChangeProperty(preplace, window, atom('_MOTIF_WM_HINTS'),
                                 atom('_MOTIF_WM_HINTS'), 32, 5, packed)

def set_hints_checked(window, flags, function=Function._None,
                      decoration=Decoration._None, input=Input.Modeless,
                      status=Status.TearoffWindow):
    packed = _pack_hints(flags, function, decoration, input, status)
    return c.core.ChangePropertyChecked(preplace, window,
                                        atom('_MOTIF_WM_HINTS'),
                                        atom('_MOTIF_WM_HINTS'), 32, 5, packed)

Module variables

var c

var preplace

Functions

def get_hints(

window)

def get_hints(window):
    return MotifHintsCookie(util.get_property(window, '_MOTIF_WM_HINTS'))

def get_hints_unchecked(

window)

def get_hints_unchecked(window):
    cook = util.get_property_unchecked(window, '_MOTIF_WM_HINTS')
    return MotifHintsCookie(cook)

def set_hints(

window, flags, function=0, decoration=0, input=0, status=1)

def set_hints(window, flags, function=Function._None,
              decoration=Decoration._None, input=Input.Modeless,
              status=Status.TearoffWindow):
    packed = _pack_hints(flags, function, decoration, input, status)
    return c.core.ChangeProperty(preplace, window, atom('_MOTIF_WM_HINTS'),
                                 atom('_MOTIF_WM_HINTS'), 32, 5, packed)

def set_hints_checked(

window, flags, function=0, decoration=0, input=0, status=1)

def set_hints_checked(window, flags, function=Function._None,
                      decoration=Decoration._None, input=Input.Modeless,
                      status=Status.TearoffWindow):
    packed = _pack_hints(flags, function, decoration, input, status)
    return c.core.ChangePropertyChecked(preplace, window,
                                        atom('_MOTIF_WM_HINTS'),
                                        atom('_MOTIF_WM_HINTS'), 32, 5, packed)

Classes

class Decoration

class Decoration:
    _None = 0
    All = 1 << 0
    Border = 1 << 1
    ResizeH = 1 << 2
    Title = 1 << 3
    Menu = 1 << 4
    Minimize = 1 << 5
    Maximize = 1 << 6

Ancestors (in MRO)

Class variables

var All

var Border

var Maximize

var Menu

var Minimize

var ResizeH

var Title

class Function

class Function:
    _None = 0
    All = 1 << 0
    Resize = 1 << 1
    Move = 1 << 2
    Minimize = 1 << 3
    Maximize = 1 << 4
    Close = 1 << 5

Ancestors (in MRO)

Class variables

var All

var Close

var Maximize

var Minimize

var Move

var Resize

class Hint

class Hint:
    Functions = 1 << 0
    Decorations = 1 << 1
    InputMode = 1 << 2
    Status = 1 << 3

Ancestors (in MRO)

Class variables

var Decorations

var Functions

var InputMode

var Status

class Input

class Input:
    Modeless = 0
    PrimaryApplicationModal = 1
    SystemModal = 2
    FullApplicationModal = 3

Ancestors (in MRO)

Class variables

var FullApplicationModal

var Modeless

var PrimaryApplicationModal

var SystemModal

class MotifHintsCookie

class MotifHintsCookie(util.PropertyCookie):
    def reply(self):
        v = util.PropertyCookie.reply(self)

        if not v:
            return None

        return {
            'flags': {
                'Functions': v[0] & Hint.Functions > 0,
                'Decorations': v[0] & Hint.Decorations > 0,
                'InputMode': v[0] & Hint.InputMode > 0,
                'Status': v[0] & Hint.Status > 0
            },
            'function': v[1],
            'decoration': v[2],
            'input': v[3],
            'status': v[4]
        }

Ancestors (in MRO)

Methods

def __init__(

self, cookie)

def __init__(self, cookie):
    self.cookie = cookie

def check(

self)

def check(self):
    return self.cookie.check()

def reply(

self)

def reply(self):
    v = util.PropertyCookie.reply(self)
    if not v:
        return None
    return {
        'flags': {
            'Functions': v[0] & Hint.Functions > 0,
            'Decorations': v[0] & Hint.Decorations > 0,
            'InputMode': v[0] & Hint.InputMode > 0,
            'Status': v[0] & Hint.Status > 0
        },
        'function': v[1],
        'decoration': v[2],
        'input': v[3],
        'status': v[4]
    }

class Status

class Status:
    TearoffWindow = 1 << 0

Ancestors (in MRO)

Class variables

var TearoffWindow