visualizations

Programmatic visualizations
git clone git://git.laack.co/visualizations.git
Log | Files | Refs | README

background.cpp (1355B)


      1 #include <cstddef>
      2 #include <cstdint>
      3 #include <stdexcept>
      4 #include <string>
      5 #include <vector>
      6 #include <X11/Xlib.h>
      7 #include <X11/Xatom.h>
      8 #include <unistd.h>
      9 
     10 std::vector<uint32_t> getScreenSize() {
     11     Display* dpy;
     12     Screen* screen;
     13     dpy = XOpenDisplay(NULL);
     14     int count = ScreenCount(dpy);
     15     if(count == 0) {
     16         throw std::runtime_error{"Unable to find screens."};
     17     }
     18     screen = ScreenOfDisplay(dpy, 0);
     19     std::vector<uint32_t> res {(uint32_t)screen->width, (uint32_t)screen->height};
     20     return res;
     21 }
     22 
     23 void sendToBg(std::string name)
     24 {
     25     Display* d = XOpenDisplay(nullptr);
     26     Window root = DefaultRootWindow(d), r, p, *kids;
     27     uint32_t n;
     28 
     29     XQueryTree(d, root, &r, &p, &kids, &n);
     30     for (unsigned i = 0; i < n; i++) {
     31 
     32         char* wn = nullptr;
     33         XFetchName(d, kids[i], &wn);
     34 
     35         if (wn == nullptr) {
     36             continue;
     37         }
     38 
     39         bool hit = name == wn;
     40         XFree(wn);
     41 
     42         if (!hit) {
     43             continue;
     44         }
     45 
     46         XSetWindowAttributes a;
     47 
     48         a.override_redirect = True;
     49         XChangeWindowAttributes(d, kids[i], CWOverrideRedirect, &a);
     50 
     51         // have to do unmap / map to make it bg for all tags
     52         XUnmapWindow(d, kids[i]);
     53         XMapWindow(d, kids[i]);
     54 
     55         XLowerWindow(d, kids[i]);
     56         break;
     57     }
     58 
     59     XFree(kids);
     60     XCloseDisplay(d);
     61 }