def test_herbstluftwm_replace(hlwm_spawner, xvfb):
    hlwm_proc_old = hlwm_spawner(display=xvfb.display)
    hlwm_old = conftest.HlwmBridge(xvfb.display, hlwm_proc_old)
    assert hlwm_old.call('echo ping').stdout == 'ping\n'

    hlwm_proc_new = hlwm_spawner(display=xvfb.display, args=['--replace'])

    # --replace should make the old hlwm process shut down:
    hlwm_proc_old.proc.wait(PROCESS_SHUTDOWN_TIME)

    # connect to new process
    hlwm_new = conftest.HlwmBridge(xvfb.display, hlwm_proc_new)
    assert hlwm_new.call('echo ping').stdout == 'ping\n'

    hlwm_proc_new.shutdown()
Exemple #2
0
def test_client_initially_on_desktop(hlwm_spawner, x11, desktops,
                                     client2desktop):
    desktop_names = ['tag{}'.format(i) for i in range(0, desktops)]
    x11.set_property_textlist('_NET_DESKTOP_NAMES', desktop_names)
    clients = []
    for desktop_idx in client2desktop:
        handle, winid = x11.create_client(sync_hlwm=False)
        clients.append(winid)
        if desktop_idx is not None:
            x11.set_property_cardinal('_NET_WM_DESKTOP', [desktop_idx],
                                      window=handle)
    x11.display.sync()

    hlwm_proc = hlwm_spawner()
    hlwm = conftest.HlwmBridge(os.environ['DISPLAY'], hlwm_proc)

    for client_idx, desktop_idx in enumerate(client2desktop):
        winid = clients[client_idx]
        if desktop_idx is not None and desktop_idx in range(0, desktops):
            assert hlwm.get_attr(f'clients.{winid}.tag') \
                == desktop_names[desktop_idx]
        else:
            assert hlwm.get_attr(f'clients.{winid}.tag') \
                == desktop_names[0]

    hlwm_proc.shutdown()
Exemple #3
0
def test_detect_monitors_xrandr(hlwm_spawner, screens, xvfb):
    args = ['-extension', 'XINERAMA']
    args += ['+extension', 'RANDR']
    with MultiscreenDisplay(server='Xephyr', screens=screens,
                            extra_args=args) as xserver:
        # boot up hlwm
        hlwm_proc = hlwm_spawner(display=xserver.display)
        hlwm = conftest.HlwmBridge(xserver.display, hlwm_proc)

        # for the debugging if something fails:
        lines = hlwm.call('detect_monitors --list-all').stdout.splitlines()
        for cur_line in lines:
            words = cur_line.split(' ')
            if words[0] == 'xinerama:':
                # check that xinerama is disabled
                assert len(words) == 1
            elif words[0] == 'xrandr:':
                # unfortunately, xrandr in Xephyr only reports the first screen
                assert len(words) == 2
                assert words[1] == Rectangle(
                    x=0, y=0, width=screens[0][0],
                    height=screens[0][1]).to_user_str()
            else:
                assert False, f"unknown detect_monitors output: {cur_line}"

        hlwm_proc.shutdown()
Exemple #4
0
def test_detect_monitors_xinerama(hlwm_spawner, server_type, screens, xvfb):
    args = ['+extension', 'XINERAMA']
    args += ['-extension', 'RANDR']
    with MultiscreenDisplay(server=server_type,
                            screens=screens,
                            extra_args=args) as xserver:
        # boot up hlwm
        hlwm_proc = hlwm_spawner(display=xserver.display)
        hlwm = conftest.HlwmBridge(xserver.display, hlwm_proc)
        # create enough tags
        hlwm.call('chain , add tag1 , add tag2 , add tag3')
        assert hlwm.get_attr('monitors.count') == '1'

        hlwm.call('detect_monitors --no-disjoin')
        # for the debugging if something fails:
        hlwm.call('detect_monitors --list-all')

        # check number of monitors
        assert len(screens) == len(xserver.screens())
        assert hlwm.get_attr('monitors.count') == str(len(screens))
        # check the position and size of monitors
        for idx, expected_geo in enumerate(xserver.screens()):
            monrect = hlwm.call(['monitor_rect', idx]).stdout.split(' ')
            assert expected_geo == [int(v) for v in monrect]

        hlwm_proc.shutdown()
def test_compositing_manager_detection_on_startup(hlwm_spawner, x11, xvfb, with_compositor):
    compositor = FakeCompositor(x11)
    if with_compositor:
        compositor.set_active(True)
    else:
        # start and shut down again
        compositor.set_active(True)
        compositor.set_active(False)

    hlwm_proc = hlwm_spawner()
    hlwm = conftest.HlwmBridge(os.environ['DISPLAY'], hlwm_proc)

    hlwm.attr.tags.focus.floating = True
    handle, _ = x11.create_client()

    hlwm.attr.theme.color = '#84cc4019'
    color_plain = (0x84, 0xcc, 0x40)
    color_premultiplied = FakeCompositor.rgb_premultiply_alpha(color_plain, 0x19)
    hlwm.attr.theme.border_width = 10
    hlwm.attr.theme.outer_width = 0

    img = x11.decoration_screenshot(handle)
    # just pick any pixel from the decoration, it shouldn't matter which:
    for x in range(0, 8):
        for y in range(0, 8):
            assert img.pixel(0, 0) == img.pixel(x, y)

    if with_compositor:
        assert img.pixel(0, 0) == color_premultiplied
    else:
        assert img.pixel(0, 0) == color_plain
def test_herbstluftwm_quit(hlwm_spawner, xvfb):
    hlwm_proc = hlwm_spawner(display=xvfb.display)
    hlwm = conftest.HlwmBridge(xvfb.display, hlwm_proc)

    assert hlwm.call('echo ping').stdout == 'ping\n'

    hlwm.call('quit')

    hlwm_proc.proc.wait(PROCESS_SHUTDOWN_TIME)
def test_manage_transient_for_windows_on_startup(hlwm_spawner, x11):
    master_win, master_id = x11.create_client(sync_hlwm=False)
    dialog_win, dialog_id = x11.create_client(sync_hlwm=False)
    dialog_win.set_wm_transient_for(master_win)
    x11.display.sync()

    hlwm_proc = hlwm_spawner()
    hlwm = conftest.HlwmBridge(os.environ['DISPLAY'], hlwm_proc)

    assert hlwm.list_children('clients') \
        == sorted([master_id, dialog_id, 'focus'])
    hlwm_proc.shutdown()
Exemple #8
0
def test_read_desktop_names(hlwm_spawner, x11, utf8names, desktop_names):
    x11.set_property_textlist('_NET_DESKTOP_NAMES', desktop_names, utf8=utf8names)
    x11.display.sync()

    hlwm_proc = hlwm_spawner()
    hlwm = conftest.HlwmBridge(os.environ['DISPLAY'], hlwm_proc)

    desktop_names = [dn for dn in desktop_names if len(dn) > 0]

    assert hlwm.list_children('tags.by-name') == sorted(desktop_names)
    for idx, name in enumerate(desktop_names):
        assert hlwm.get_attr(f'tags.{idx}.name') == name

    hlwm_proc.shutdown()
def test_client_initially_on_desktop(hlwm_spawner, x11, desktops,
                                     client2desktop):
    desktop_names = ['tag{}'.format(i) for i in range(0, desktops)]
    x11.set_property_textlist('_NET_DESKTOP_NAMES', desktop_names)
    clients = []
    for desktop_idx in client2desktop:
        winHandle, winid = x11.create_client(sync_hlwm=False)
        clients.append(winid)
        if desktop_idx is not None:
            x11.set_property_cardinal('_NET_WM_DESKTOP', [desktop_idx],
                                      window=winHandle)
    x11.display.sync()

    hlwm_proc = hlwm_spawner()
    hlwm = conftest.HlwmBridge(os.environ['DISPLAY'], hlwm_proc)

    for client_idx, desktop_idx in enumerate(client2desktop):
        winid = clients[client_idx]
        if desktop_idx is not None and desktop_idx in range(0, desktops):
            assert hlwm.get_attr(f'clients.{winid}.tag') \
                == desktop_names[desktop_idx]
        else:
            assert hlwm.get_attr(f'clients.{winid}.tag') \
                == desktop_names[0]

    # check that clients.focus matches the X11 input focus on all tags:
    for i in range(0, desktops):
        assert i == hlwm.attr.tags.focus.index()
        input_focus = x11.display.get_input_focus().focus
        if 'focus' in hlwm.list_children('clients'):
            # if a client is focused according to hlwm, it has the input focus:
            assert x11.winid_str(
                input_focus) == hlwm.attr.clients.focus.winid()
        else:
            # otherwise, the invisible hlwm dummy window is focused:
            assert input_focus.id == x11.get_property(
                '_NET_SUPPORTING_WM_CHECK')[0]
        hlwm.call('use_index +1')

    hlwm_proc.shutdown()
Exemple #10
0
def test_detect_monitors_deduplication(hlwm_spawner, screens, xvfb):
    args = ['+extension', 'XINERAMA']
    args += ['-extension', 'RANDR']
    # Xvfb puts all screens at position (0,0),
    # so we use it to verify that detect_monitors removes duplicates
    # while preserving the order
    with MultiscreenDisplay(server='Xvfb', screens=screens,
                            extra_args=args) as xserver:
        # boot up hlwm
        hlwm_proc = hlwm_spawner(display=xserver.display)
        hlwm = conftest.HlwmBridge(xserver.display, hlwm_proc)
        # create enough tags
        hlwm.call('chain , add tag1 , add tag2 , add tag3')
        assert hlwm.get_attr('monitors.count') == '1'
        rects = hlwm.call(['detect_monitors', '-l']).stdout.splitlines()
        expected = [
            Rectangle(0, 0, s[0], s[1]).to_user_str()
            for idx, s in enumerate(screens) if screens.index(s) == idx
        ]

        assert rects == expected

        hlwm_proc.shutdown()