Exemple #1
0
    def get_text(self):
        display = window.get_platform().get_default_display()._display
        owner = xlib.XGetSelectionOwner(display, XA_PRIMARY)
        if not owner:
            return ''

        # TODO: xa_utf8_string
        xlib.XConvertSelection(display, XA_PRIMARY, XA_STRING, 0, owner,
                               CurrentTime)
        xlib.XFlush(display)

        # determine what's in the selection buffer
        type = xlib.Atom()
        format = c_int()
        len = c_ulong()
        bytes_left = c_ulong()
        data = POINTER(c_ubyte)()
        xlib.XGetWindowProperty(display, owner, XA_STRING, 0, 0, 0,
                                AnyPropertyType, byref(type), byref(format),
                                byref(len), byref(bytes_left), byref(data))

        length = int(bytes_left.value)
        if not length:
            return ''

        # get the contents
        dummy = c_ulong()
        xlib.XGetWindowProperty(display, owner, XA_STRING, 0, length, 0,
                                AnyPropertyType, byref(type), byref(format),
                                byref(len), byref(dummy), byref(data))
        s = ''.join(chr(c) for c in data[:len.value])
        xlib.XFree(data)
        return s
Exemple #2
0
 def get_screens(self):
     x_screen = xlib.XDefaultScreen(self._display)
     if _have_xinerama and xinerama.XineramaIsActive(self._display):
         number = c_int()
         infos = xinerama.XineramaQueryScreens(self._display, byref(number))
         infos = cast(infos,
                      POINTER(xinerama.XineramaScreenInfo *
                              number.value)).contents
         result = []
         for info in infos:
             result.append(
                 XlibScreen(self, x_screen, info.x_org, info.y_org,
                            info.width, info.height, True))
         xlib.XFree(infos)
         return result
     else:
         # No xinerama
         screen_count = xlib.XScreenCount(self._display)
         result = []
         for i in range(screen_count):
             screen = xlib.XScreenOfDisplay(self._display, i)
             result.append(
                 XlibScreen(self, i, 0, 0, screen.contents.width,
                            screen.contents.height, False))
         # Move default screen to be first in list.
         s = result.pop(x_screen)
         result.insert(0, s)
         return result
Exemple #3
0
    def _validate(self):
        if not self.invalid:
            return

        count = ctypes.c_int()
        modes = ctypes.POINTER(ctypes.POINTER(xf86vmode.XF86VidModeModeInfo))()
        xf86vmode.XF86VidModeGetAllModeLines(self.x_display, self.x_screen,
                                             count, modes)

        # Copy modes out of list and free list
        self.modes = list()
        for i in range(count.value):
            mode = xf86vmode.XF86VidModeModeInfo()
            ctypes.memmove(ctypes.byref(mode), ctypes.byref(modes.contents[i]),
                           ctypes.sizeof(mode))
            self.modes.append(mode)
            if mode.privsize:
                xlib.XFree(mode.private)
        xlib.XFree(modes)

        self.invalid = False
Exemple #4
0
def make_window(dpy, name, x,y, width, height):
    attrib = (ctypes.c_int * 11)(
        GLX_RGBA,
        GLX_RED_SIZE, 1,
        GLX_GREEN_SIZE, 1,
        GLX_BLUE_SIZE, 1,
        GLX_DOUBLEBUFFER,
        GLX_DEPTH_SIZE, 1,
        0)

    scrnum = xlib.XDefaultScreen(dpy)
    root = xlib.XRootWindow(dpy, scrnum)

    visinfo = glXChooseVisual(dpy, scrnum, attrib)
    
    attr = xlib.XSetWindowAttributes()
    attr.background_pixel = 0
    attr.border_pixel = 0
    attr.colormap = xlib.XCreateColormap(dpy, root, visinfo.contents.visual,
        xlib.AllocNone)
    attr.event_mask = (xlib.StructureNotifyMask | 
                       xlib.ExposureMask |
                       xlib.KeyPressMask)
    mask = (xlib.CWBackPixel |
            xlib.CWBorderPixel | 
            xlib.CWColormap | 
            xlib.CWEventMask)

    win = xlib.XCreateWindow(dpy, root, 0, 0, width, height, 0, 
                             visinfo.contents.depth, xlib.InputOutput,
                             visinfo.contents.visual, mask, attr)

    sizehints = xlib.XSizeHints()
    sizehints.x = x
    sizehints.y = y
    sizehints.width = width
    sizehints.height = height
    sizehints.flags = xlib.USSize | xlib.USPosition
    xlib.XSetNormalHints(dpy, win, sizehints)
    xlib.XSetStandardProperties(dpy, win, name, name, 0, None, 0, sizehints)

    ctx = glXCreateContext(dpy, visinfo, None, True)
    xlib.XFree(visinfo)

    return win, ctx