summaryrefslogtreecommitdiffstats
path: root/main.c
blob: a12b611a944cf6cab6af9959f10f9f1580fac49c (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
#include <stdio.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>


int main(void) {
  union {
    XEvent xev;
    XRRScreenChangeNotifyEvent xrrev;
  } result;
  //XRRScreenChangeNotifyEvent xev;
  //XWindowAttributes focus_attrs, root_attrs;

  Display *display = XOpenDisplay(NULL);

  Window focus;
  int revert_to;
  XGetInputFocus(display, &focus, &revert_to);

  printf("focus: %lx\n", focus);

  //Window root = XDefaultRootWindow(display);

  int xrr_event_base;
  int xrr_error_base;
  // TODO int hasXrandR =
  XRRQueryExtension(display, &xrr_event_base, &xrr_error_base);

  // TODO if has RR
  XRRSelectInput(display, XDefaultRootWindow(display), RRScreenChangeNotifyMask);


  for (;;) {

    //XGetWindowAttributes(display, focus, &focus_attrs);

    //printf("a\n");

    //XWindowEvent(display, root, RRScreenChangeNotifyMask, (XEvent *)&xev);
    XNextEvent(display, &result.xev);

    if (result.xev.type == (xrr_event_base + RRScreenChangeNotify)) {
      // cannot resize root window
      if (focus != 0x1) {
        XMoveResizeWindow(display, focus, 0, 0, result.xrrev.width, result.xrrev.height);
      }
    }

    //printf("derp\n");

    //XFlush(display);
  }

  //XFlush(display);
}