Beispiel #1
0
def close_x():
    '''
    Closes the connection to X, but flushes it first
    '''
    global display
    display.flush()
    display.close()
Beispiel #2
0
def close_x():
    '''
    Closes the connection to X, but flushes it first
    '''
    global display
    display.flush()
    display.close()
def blink(display, win, gc, cols):
    while 1:
        time.sleep(2)
        print 'Changing color', cols[0]
        gc.change(foreground = cols[0])
        cols = (cols[1], cols[0])
        redraw(win, gc)
        display.flush()
def blink(display, win, gc, cols):
    while 1:
        time.sleep(2)
        print('Changing color', cols[0])
        gc.change(foreground=cols[0])
        cols = (cols[1], cols[0])
        redraw(win, gc)
        display.flush()
def reset(display, win):
    win.set_wm_normal_hints(
        flags = Xutil.PWinGravity,
        win_gravity = X.NorthWestGravity)
    atom = lambda s: display.intern_atom(s)
    send_event(display.screen().root, win, atom("_NET_WM_STATE"),
               [0, atom("_NET_WM_STATE_MAXIMIZED_VERT"),
                atom("_NET_WM_STATE_MAXIMIZED_HORZ")])
    display.flush()
Beispiel #6
0
def handle_keypress(display, root_window, HM):
    '''Grabs the keyboard and listens for compose_map sequences'''
    global compose_map
    root_window.grab_keyboard(True, X.GrabModeAsync, X.GrabModeAsync,
                              X.CurrentTime)

    #   these will hold our input
    myinput = ""  # in sequences of <KEYSYM> (possible keys to compose_map)
    myascii = []  # as ascii to be sent as input if composing fails
    myinput2 = []  # list of KEYSIM

    while True:  # loop until explicit break
        event = root_window.display.next_event()
        hookevent = HM.processevents(
            event)  # process the event, takes care of shift, and other crap

        if event.type == X.KeyRelease:  # act on keypresses only
            if hookevent.Printable:  # this event contains a "printable" character
                if HM.ison['shift']:
                    event = root_window.display.next_event()
                    HM.processevents(event)
                    myascii.append((Shift_L, hookevent.ScanCode))
                else:
                    myascii.append(hookevent.ScanCode)
                myinput += '<%s>' % hookevent.Key  # add the <KEYSYM> to myinput
                myinput2.append(hookevent.Key)

                if myinput in compose_map.keys(
                ):  # the compose_map contains a translation

                    stop_grab(display)  # we stop the grab
                    print(
                        'Match found. Sending "{}" to active window...'.format(
                            myinput))
                    send_sequence(display, root_window, myinput2)
                    display.flush()

                    return  # our job is done

                if not possible_match(myinput):

                    print('No match found. sending "{}" to active window...'.
                          format(myinput))
                    stop_grab(display)
                    for k in myascii:
                        send_key(root_window, k)

                    return

            if event.detail == 9:
                # Esc pressed, ungrab keyboard
                stop_grab(display)
                HM.is_running = False  # comment this when everything is working ?
                return
Beispiel #7
0
def main(argv):

    bg_size = 16  # Default corner size
    corners = ['nw', 'ne', 'se', 'sw']  # Default corners to draw

    try:
        opts, args = getopt.getopt(argv, "h", ["help", "corners=", "size="])
    except:
        return usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            return usage()
        elif opt in ("--corners"):
            corners = ''.join(str(arg)).lower()
            if not any(sz in corners for sz in ["nw", "ne", "sw", "se"]):
                return usage()
        elif opt in ("--size"):
            try:
                bg_size = int(arg)
            except:
                return usage()

    for arg in sys.argv:
        print(arg)

    window = create_window(
        bg_size, corners)  # Make the window using specified size / corners
    window.map()  # Make the window appear

    while True:
        e = display.next_event()

        set_wm_state(window, "_NET_WM_DESKTOP",
                     data=[0xFFFFFFFF, 1, 0, 0,
                           0])  # Keeps window on all workspaces
        set_wm_state(window,
                     "_NET_WM_STATE",
                     data=[1, "_NET_WM_STATE_SKIP_TASKBAR", 0, 1,
                           0])  # Removes window from task list
        set_wm_state(window,
                     "_NET_WM_STATE",
                     data=[1, "_NET_WM_STATE_ABOVE", 0, 1,
                           0])  # Keeps window above (almost all) other windows

        # TODO: How to keep above fullscreened windows (F11 sublime / chrome / etc.) ? This doesn't work:
        # set_wm_state(window, "_NET_WM_STATE", data=[1, "_NET_WM_STATE_FULLSCREEN", 0, 1, 0])

        display.flush()  # Is this really needed? Seems to work fine without
Beispiel #8
0
 def invalidate(self):
     '''
     Cause the window to be redraw on the main window
     '''
     # Dummy event for performing update in the main thread # TODO do this better
     e = Xlib.protocol.event.KeyPress(detail = 1,
                                      time = Xlib.X.CurrentTime,
                                      root = display.screen().root,
                                      window = self.window,
                                      child = Xlib.X.NONE,
                                      root_x = 1, root_y = 1,
                                      event_x = 1, event_y = 1,
                                      state = 0, same_screen = 1)
     display.send_event(self.window, e)
     display.flush()
Beispiel #9
0
def pick_coordinate(display, cursor):
    """Changes the cursor and grabs the pointer for every window.

    Args:
        display: Xlib display
        cursor: cursor object or X.NONE
    """
    try:
        display.screen().root.grab_pointer(
            0, X.PointerMotionMask | X.ButtonReleaseMask | X.ButtonPressMask,
            X.GrabModeAsync, X.GrabModeAsync, X.NONE, cursor, X.CurrentTime)
        display.flush()
        yield
    finally:
        display.ungrab_pointer(0)
        display.flush()
Beispiel #10
0
 def invalidate(self):
     '''
     Cause the window to be redraw on the main window
     '''
     # Dummy event for performing update in the main thread # TODO do this better
     e = Xlib.protocol.event.KeyPress(detail=1,
                                      time=Xlib.X.CurrentTime,
                                      root=display.screen().root,
                                      window=self.window,
                                      child=Xlib.X.NONE,
                                      root_x=1,
                                      root_y=1,
                                      event_x=1,
                                      event_y=1,
                                      state=0,
                                      same_screen=1)
     display.send_event(self.window, e)
     display.flush()
Beispiel #11
0
 def map(self):
     '''
     Map the window
     '''
     self.window.map()
     display.flush()
Beispiel #12
0
def move(x, y):
    display = Xlib.display.Display()
    Xlib.ext.xtest.fake_input(display, Xlib.X.MotionNotify, x=x, y=y)
    display.flush()
Beispiel #13
0
def switch_desktop(index):
    display = Xlib.display.Display()
    sendEvent(display.screen().root,
              display.intern_atom("_NET_CURRENT_DESKTOP"),
              [index, X.CurrentTime])
    display.flush()
Beispiel #14
0
                                           client_type=ctype,
                                           data=(32, (data)))
    if not mask:
        mask = (X.SubstructureRedirectMask | X.SubstructureNotifyMask)
    root.send_event(ev, event_mask=mask)


# connect shadowsocks

display = Xlib.display.Display()
screen = display.screen()
root = screen.root

sendEvent(root, display.intern_atom("_NET_CURRENT_DESKTOP"),
          [0, X.CurrentTime])
display.flush()
webbrowser.open('https://duckduckgo.com/')

# switch to desktop 2
# open ide
sendEvent(root, display.intern_atom("_NET_CURRENT_DESKTOP"),
          [1, X.CurrentTime])
display.flush()
subprocess.call(["bash", "/opt/pycharm/bin/pycharm.sh"])
# subprocess.call(["bash", "/opt/phpstorm/bin/phpstorm.sh"])

# switch to desktop 3
# open terminal
sendEvent(root, display.intern_atom("_NET_CURRENT_DESKTOP"),
          [2, X.CurrentTime])
display.flush()
Beispiel #15
0
def draw_it():
  root.draw_text(gc, 100, 100, b"Hello, world!")
  display.flush()
Beispiel #16
0
def stop_grab(display):
    display.ungrab_keyboard(X.CurrentTime)
    display.flush()
Beispiel #17
0
def stop_grab(display):
    '''
    Free the keyboard
    '''
    display.ungrab_keyboard(X.CurrentTime)
    display.flush()
Beispiel #18
0
    code = compile(code, config_file, 'exec')
    g, l = globals(), dict(locals())
    for key in l:
        g[key] = l[key]
    exec(code, g)
else:
    print('No configuration file found')
    sys.exit(1)


open_x()
display = get_display()
outputs = get_monitors()
start()

while True:
    try:
        e = display.next_event()
        if e.type == Xlib.X.DestroyNotify:
            break
        else:
            unhandled_event(e)
    except KeyboardInterrupt:
        break
    redraw()
    display.flush()

stop()
close_x()

Beispiel #19
0
 def map(self):
     '''
     Map the window
     '''
     self.window.map()
     display.flush()