]> git.mdlowis.com Git - projs/tide.git/commitdiff
added scaffolding for multiple desktops
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 17 Aug 2019 04:04:21 +0000 (00:04 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 17 Aug 2019 04:04:21 +0000 (00:04 -0400)
src/anvil.c

index 1cb4912831d9d643667ee87e8fe3aefbd4065e6d..8c5ba566739eaed9e933f10a7734cfd5ccdc85d2 100644 (file)
@@ -52,14 +52,19 @@ typedef struct Column {
     int flags, x, w;
 } Column;
 
+struct {
+    Node *floated, *tiled;
+} Desktops[10] = {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}};
+int Desktop = 0;
+
 XConf X = {0};
 Node* All_Clients = NULL;
-Node* Tiled_Clients = NULL;
 Cursor Move_Cursor;
 Cursor Main_Cursor;
 int StartY = 0;
 
-Column* Columns = NULL;
+#define Tiled_Clients (Desktops[Desktop].tiled)
+#define Floated_Clients (Desktops[Desktop].floated)
 
 /* configuration */
 uint32_t BorderWidth = 1;
@@ -71,6 +76,55 @@ Atom
     XA_NET_WM_WINDOW_TYPE_DIALOG,
     XA_WM_PROTOCOLS;
 
+typedef union {
+    const char** com;
+    const int i;
+} Arg;
+
+struct key {
+    unsigned int mod;
+    KeySym keysym;
+    void (*function)(const Arg arg);
+    const Arg arg;
+};
+
+void change_desktop(const Arg arg);
+void client_to_desktop(const Arg arg);
+
+#define MOD Mod1Mask
+
+// Avoid multiple paste
+#define DESKTOPCHANGE(K,N) \
+    {  MOD,           K, change_desktop, {.i = N}}, \
+    {  MOD|ShiftMask, K, client_to_desktop, {.i = N}},
+
+// Shortcuts
+static struct key keys[] = {
+    // MOD              KEY                         FUNCTION        ARGS
+//    {  MOD,             XK_c,                       spawn,          {.com = lockcmd}},
+//    {  MOD,             XK_p,                       spawn,          {.com = dmenucmd}},
+//    {  MOD|ShiftMask,   XK_Return,                  spawn,          {.com = urxvtcmd}},
+       DESKTOPCHANGE(   XK_0,                                       0)
+       DESKTOPCHANGE(   XK_1,                                       1)
+       DESKTOPCHANGE(   XK_2,                                       2)
+       DESKTOPCHANGE(   XK_3,                                       3)
+       DESKTOPCHANGE(   XK_4,                                       4)
+       DESKTOPCHANGE(   XK_5,                                       5)
+       DESKTOPCHANGE(   XK_6,                                       6)
+       DESKTOPCHANGE(   XK_7,                                       7)
+       DESKTOPCHANGE(   XK_8,                                       8)
+       DESKTOPCHANGE(   XK_9,                                       9)
+//    {  MOD,             XK_q,                       quit,           {NULL}}
+};
+
+void change_desktop(const Arg arg) {
+    Desktop = arg.i;
+}
+
+void client_to_desktop(const Arg arg) {
+    printf("send to desktop %d\n", arg.i);
+}
+
 /* Utility Functions
  *****************************************************************************/
 void die(char* errstr) {
@@ -163,12 +217,16 @@ void client_add(Client* parent, Client* c) {
     list_add(&All_Clients, NULL, &(c->mnode));
     if (!client_flags(c, FLOATING))
         list_add(&Tiled_Clients, (parent ? &(parent->tnode) : NULL), &(c->tnode));
+    else
+        list_add(&Floated_Clients, NULL, &(c->tnode));
 }
 
 void client_del(Client* c) {
     list_del(&All_Clients, &(c->mnode));
     if (!client_flags(c, FLOATING))
         list_del(&Tiled_Clients, &(c->tnode));
+    else
+        list_del(&Floated_Clients, &(c->tnode));
 }
 
 void client_redraw(XConf* x, Client* c) {
@@ -473,6 +531,15 @@ static void xexpose(XConf* x, XEvent* e) {
         client_redraw(x, c);
 }
 
+#include <X11/XKBlib.h>
+static void xkeypress(XConf* x, XEvent* e) {
+    KeySym keysym = XkbKeycodeToKeysym(
+        x->display, e->xkey.keycode, 0, 0);
+    for (size_t i = 0; i < nelem(keys); i++)
+        if(keys[i].keysym == keysym && keys[i].mod == e->xkey.state)
+            keys[i].function(keys[i].arg);
+}
+
 #pragma GCC diagnostic pop
 
 int main(void) {
@@ -493,9 +560,15 @@ int main(void) {
     Move_Cursor = XCreateFontCursor(X.display, XC_draped_box);
     XDefineCursor(X.display, X.root, Main_Cursor);
 
+    KeyCode code;
+    for (size_t i = 0; i < nelem(keys); i++)
+        if ((code = XKeysymToKeycode(X.display, keys[i].keysym)))
+            XGrabKey(X.display, code, keys[i].mod, X.root, True, GrabModeAsync, GrabModeAsync);
+
     /* register e vent handlers */
     X.eventfns[ButtonPress] = xbtnpress;
     X.eventfns[ButtonRelease] = xbtnrelease;
+    X.eventfns[KeyPress] = xkeypress;
     X.eventfns[ConfigureRequest] = xconfigrequest;
     X.eventfns[MapRequest] = xmaprequest;
     X.eventfns[UnmapNotify] = xunmapnotify;