Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 3.39 KB | None | 0 0
  1. import std.stdio, std.string, std.algorithm, std.array, xcb.xcb;
  2. import core.stdc.stdlib;
  3.  
  4. enum WIDTH = 1920;
  5. enum HEIGHT = 25;
  6.  
  7. union rgba_t {
  8.   struct { ubyte b, g, r, a; }
  9.   uint v;
  10. }
  11.  
  12. /*
  13.   Most of this is copied from lemonbar
  14. */
  15.  
  16. void main() {
  17.   xcb_connection_t* connection = xcb_connect(null, null);
  18.   const xcb_setup_t* setup     = xcb_get_setup(connection);
  19.   xcb_screen_iterator_t iter   = xcb_setup_roots_iterator(setup);
  20.   xcb_screen_t* screen         = iter.data;
  21.   xcb_window_t window          = xcb_generate_id(connection);
  22.   rgba_t bgc                   = {0xff, 0, 0, 0x0};
  23.   xcb_pixmap_t pixmap          = xcb_generate_id(connection);
  24.   xcb_gcontext_t gc;
  25.  
  26.  
  27.   ubyte depth = 32;
  28.   uint thing = 1;
  29.  
  30.   xcb_create_window(connection,
  31.                     XCB_COPY_FROM_PARENT,
  32.                     window,
  33.                     screen.root,
  34.                     0, 0,
  35.                     WIDTH, HEIGHT,
  36.                     0,
  37.                     XCB_WINDOW_CLASS_INPUT_OUTPUT,
  38.                     screen.root_visual,
  39.                     XCB_CW_OVERRIDE_REDIRECT,
  40.                     &thing);
  41.  
  42.   xcb_create_pixmap(connection, depth, pixmap, window, WIDTH, HEIGHT);
  43.  
  44.   uint[] stuff2 = [bgc.v];
  45.   xcb_create_gc(connection, gc, pixmap, XCB_GC_FOREGROUND, stuff2.ptr);
  46.  
  47.   setAtoms(connection, window);
  48.  
  49.   xcb_map_window(connection, window);
  50.  
  51.   uint[] stuff3 = [0, 0];
  52.   xcb_configure_window(connection, window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, stuff3.ptr);
  53.  
  54.   xcb_flush(connection);
  55.   readln;
  56.   xcb_disconnect(connection);
  57. }
  58.  
  59. enum NetWM {
  60.   WINDOW_TYPE = 0,
  61.   WINDOW_TYPE_DOCK,
  62.   DESKTOP,
  63.   STRUT_PARTIAL,
  64.   STRUT,
  65.   STATE,
  66.   STATE_STICKY,
  67.   STATE_ABOVE
  68. };
  69.  
  70. static immutable ATOM_NAMES = [
  71.   "_NET_WM_WINDOW_TYPE",
  72.   "_NET_WM_WINDOW_TYPE_DOCK",
  73.   "_NET_WM_DESKTOP",
  74.   "_NET_WM_STRUT_PARTIAL",
  75.   "_NET_WM_STRUT",
  76.   "_NET_WM_STATE",
  77.   "_NET_WM_STATE_STICKY",
  78.   "_NET_WM_STATE_ABOVE"
  79. ];
  80.  
  81. void setAtoms(xcb_connection_t* connection, xcb_window_t window) {
  82.   xcb_intern_atom_cookie_t[ATOM_NAMES.length] atomCookies;
  83.   xcb_atom_t[ATOM_NAMES.length] atomList;
  84.  
  85.   foreach (i; 0..ATOM_NAMES.length) {
  86.     atomCookies[i] = xcb_intern_atom(connection, 0, cast(ushort)(ATOM_NAMES[i].length), ATOM_NAMES[i].toStringz);
  87.   }
  88.  
  89.   foreach (i; 0..ATOM_NAMES.length) {
  90.     auto atomReply = xcb_intern_atom_reply(connection, atomCookies[i], null);
  91.     if (!atomReply) return;
  92.     atomList[i] = atomReply.atom;
  93.     free(atomReply);
  94.   }
  95.  
  96.   int[12] strut = [0, 0, HEIGHT, 0, 0, 0, 0, 0, 0, WIDTH, 0, 0];
  97.  
  98.   uint thing = -1;
  99.  
  100.   xcb_change_property(connection, XCB_PROP_MODE_REPLACE, window, atomList[NetWM.WINDOW_TYPE],   XCB_ATOM_ATOM,     32, 1,  &atomList[NetWM.WINDOW_TYPE_DOCK]);
  101.   xcb_change_property(connection, XCB_PROP_MODE_APPEND,  window, atomList[NetWM.STATE],         XCB_ATOM_ATOM,     32, 2,  &atomList[NetWM.STATE_STICKY]);
  102.   xcb_change_property(connection, XCB_PROP_MODE_REPLACE, window, atomList[NetWM.DESKTOP],       XCB_ATOM_CARDINAL, 32, 1,  &thing);
  103.   xcb_change_property(connection, XCB_PROP_MODE_REPLACE, window, atomList[NetWM.STRUT_PARTIAL], XCB_ATOM_CARDINAL, 32, 12, &strut);
  104.   xcb_change_property(connection, XCB_PROP_MODE_REPLACE, window, atomList[NetWM.STRUT],         XCB_ATOM_CARDINAL, 32, 4,  &strut);
  105.   xcb_change_property(connection, XCB_PROP_MODE_REPLACE, window, XCB_ATOM_WM_NAME,              XCB_ATOM_STRING,   8,  5,  "mybar".toStringz);
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement