1
/* Simple test program that does not depend on Gtk/Gdk, to show how
2
 * fullscreen etc. properties can be set. */
3
4
#include <X11/Xlib.h>
5
#include <X11/Xatom.h>
6
#include <X11/Xutil.h>
7
#include <string.h>
8
9
static void set_non_compositing (Display *display, Window xwindow)
10
{
11
        Atom atom;
12
        int one = 1;
13
14
        atom = XInternAtom (display, "_HILDON_NON_COMPOSITED_WINDOW", False);
15
16
        XChangeProperty (display,
17
                       xwindow,
18
                       atom,
19
                       XA_INTEGER, 32, PropModeReplace,
20
                       (unsigned char *) &one, 1);
21
}
22
23
static void set_fullscreen (Display *dpy, Window w)
24
{
25
  Atom wm_state, state_fs;
26
27
  wm_state = XInternAtom (dpy, "_NET_WM_STATE", False);
28
  state_fs = XInternAtom (dpy, "_NET_WM_STATE_FULLSCREEN", False);
29
30
  XChangeProperty (dpy, w, wm_state,
31
                   XA_ATOM, 32, PropModeReplace,
32
                   (unsigned char *) &state_fs, 1);
33
}
34
35
static void set_no_transitions (Display *dpy, Window w)
36
{
37
  Atom actions, no_trans;
38
39
  actions = XInternAtom (dpy, "_NET_WM_ALLOWED_ACTIONS", False);
40
  no_trans = XInternAtom (dpy, "_HILDON_WM_ACTION_NO_TRANSITIONS", False);
41
42
  XChangeProperty (dpy, w, actions,
43
                   XA_ATOM, 32, PropModeReplace,
44
                   (unsigned char *)&no_trans, 1);
45
}
46
47
static void set_window_type (Display *dpy, Window w)
48
{
49
  Atom w_type, normal;
50
51
  w_type = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE", False);
52
  normal = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NORMAL", False);
53
54
  XChangeProperty (dpy, w, w_type,
55
                   XA_ATOM, 32, PropModeReplace,
56
                   (unsigned char *) &normal, 1);
57
}
58
59
/* this can be used to set fullscreenness after mapping the window */
60
#if 0
61
static void set_fullscreen (Display *display, Window xwindow)
62
{
63
        XClientMessageEvent xclient;
64
  
65
#define _NET_WM_STATE_REMOVE        0    /* remove/unset property */
66
#define _NET_WM_STATE_ADD           1    /* add/set property */
67
#define _NET_WM_STATE_TOGGLE        2    /* toggle property  */  
68
  
69
  memset (&xclient, 0, sizeof (xclient));
70
  xclient.type = ClientMessage;
71
  xclient.window = xwindow;
72
  xclient.message_type = XInternAtom (display, "_NET_WM_STATE", False);
73
  xclient.format = 32;
74
  xclient.data.l[0] = _NET_WM_STATE_ADD;
75
  xclient.data.l[1] = XInternAtom (display, "_NET_WM_STATE_FULLSCREEN", False);
76
  xclient.data.l[2] = None;
77
  xclient.data.l[3] = 0;
78
  xclient.data.l[4] = 0;
79
  
80
  XSendEvent (display, DefaultRootWindow (display), False,
81
              SubstructureRedirectMask | SubstructureNotifyMask,
82
              (XEvent *)&xclient);
83
}
84
#endif
85
86
int main(int argc, char **argv)
87
{
88
        Display *dpy;
89
        Window w;
90
        XWMHints *wmhints;
91
92
        /* TODO: X error handling is missing */
93
94
        dpy = XOpenDisplay(NULL);
95
        w = XCreateSimpleWindow(dpy, DefaultRootWindow (dpy), 0, 0,
96
                                800, 480, 0, 0, 0);
97
98
        set_fullscreen(dpy, w);
99
        set_window_type(dpy, w);
100
101
        /* tell the window manager that we want keyboard focus */
102
        wmhints = XAllocWMHints();
103
        wmhints->input = True;
104
        wmhints->flags = InputHint;
105
        XSetWMHints(dpy, w, wmhints);
106
        XFree(wmhints);
107
108
        /* optional: disable compositing for this window to speed up */
109
        set_non_compositing(dpy, w);
110
111
        /* optional: disable compositor's transitions for this window */
112
        set_no_transitions(dpy, w);
113
114
        XMapWindow(dpy, w);  /* map the window */
115
116
        for (;;) {
117
                XEvent xev;
118
119
                /* useless main loop that just reads incoming X events */
120
                XNextEvent(dpy, &xev);
121
        }
122
123
        return 0;
124
}