summaryrefslogtreecommitdiff
path: root/wm_hints.c
blob: 87d7c01beee6770560f09a17125a301d1e1cb5d2 (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
/* Compile with "gcc -o wm_hints -Wall wm_hints.c -lX11" */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>

int main(int argc, char** argv)
{
  Display* display = XOpenDisplay(NULL);
  if (!display) {
    fprintf(stderr, "Couldn't open display\n");
    return 1;
  }
  int screen = DefaultScreen(display);

  const int width = 300, height = 200;

  unsigned long black = BlackPixel(display, screen);
  unsigned long white = WhitePixel(display, screen);

  Window win = XCreateSimpleWindow(display,
                                   RootWindow(display, screen),
                                   0,       /* x */
                                   0,       /* y */
                                   width,
                                   height,
                                   0,       /* border_width */
                                   black,   /* border */
                                   white);  /* background */

  Atom windowState = XInternAtom(display, "_NET_WM_STATE", False);
  Atom vertMaxState = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
  Atom horzMaxState = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  Atom data[2] = { vertMaxState, horzMaxState };
  XChangeProperty(display, win, windowState,  XA_ATOM, 32, PropModeReplace, (unsigned char *)data, 2);

  XMapWindow(display, win);
  XFlush(display);

  while (1) {
    printf("Setting hints\n");

    XWMHints *hints = XAllocWMHints();
    hints->flags = StateHint;
    hints->initial_state = NormalState;
    XSetWMHints(display, win, hints);
    XFree(hints);
    XFlush(display);

    sleep(20);
  }

  return 0;
}