Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib/sugar-runner-window.c
blob: 859005647ba3ffe33317070790350ca71e1d3ab0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <X11/Xlib.h>
#include <X11/Xatom.h>

#include "sugar-runner-window.h"

static Display *display = NULL;
static Window window = 0;
static Atom wm_delete_window;
static gboolean is_fullscreen = FALSE;

void
sugar_runner_window_create(int width, int height, gboolean fullscreen)
{
    Window root_window;

    if (display == NULL) {
        display = XOpenDisplay(NULL);
    }

    root_window = RootWindow(display, 0);

    window = XCreateSimpleWindow(display, root_window, 0, 0,
                                 width, height, 0, 0, 0);

    XSelectInput (display, window, StructureNotifyMask);

    if (fullscreen) {
        Atom atom;

        atom = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", True);
        XChangeProperty(display, window,
                        XInternAtom(display, "_NET_WM_STATE", True),
                        XA_ATOM, 32, PropModeReplace,
                        (unsigned char *)&atom, 1);
    }

    XMapWindow(display, window);

    wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, window, &wm_delete_window, 1);
}

gboolean
sugar_runner_window_wait(void)
{
    XEvent event;

    XNextEvent(display, &event);

    if (event.type == ConfigureNotify) {
        XConfigureEvent configure_event = event.xconfigure;
        is_fullscreen = (DisplayWidth(display, 0) == configure_event.width &&
                         DisplayHeight(display, 0) == configure_event.height);
    }

    if (event.type == ClientMessage &&
        event.xclient.data.l[0] == wm_delete_window) {
        XCloseDisplay(display);
        return FALSE;
    }

    return TRUE;
}

gboolean
sugar_runner_window_is_fullscreen(void)
{
    return is_fullscreen;
}

unsigned long
sugar_runner_window_get_xid(void)
{
    return window;
}