commit c96c574f8acfce2fcadf3687280fe13c6f5ad8fa
parent ea5c31b01e93542298adef1b487dd46cd58cccee
Author: Kebigon <git@kebigon.xyz>
Date: Thu, 9 Jul 2020 17:36:57 +0900
First try at workspace implementation
Diffstat:
| M | config.h | | | 31 | +++++++++++++++++++++---------- |
| M | kbgwm.c | | | 80 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- |
| M | types.h | | | 12 | +++++------- |
3 files changed, 101 insertions(+), 22 deletions(-)
diff --git a/config.h b/config.h
@@ -10,16 +10,28 @@ static const char* termcmd [] = { "alacritty",
static const char* menucmd [] = { "dmenu_run",
NULL };
+#define WORKSPACEKEYS(KEY,WORKSPACE) \
+ { MODKEY|XCB_MOD_MASK_SHIFT, KEY, sendToWorkspace, {.i = WORKSPACE} }, \
+ { MODKEY, KEY, changeWorkspace, {.i = WORKSPACE} },
+
static Key keys [] =
{
- { MODKEY,
- XK_Return,
- start,
- { .cmd = termcmd }},
- { MODKEY,
- XK_p,
- start,
- { .cmd = menucmd }}
+ { MODKEY, XK_Return, start, { .cmd = termcmd }},
+ { MODKEY, XK_p, start, { .cmd = menucmd }},
+ { MODKEY, XK_Page_Up, previousWorkspace, { 0 }},
+ { MODKEY, XK_Page_Down, nextWorkspace, { 0 }},
+ WORKSPACEKEYS(XK_Home, 0)
+ WORKSPACEKEYS(XK_1, 0)
+ WORKSPACEKEYS(XK_2, 1)
+ WORKSPACEKEYS(XK_3, 2)
+ WORKSPACEKEYS(XK_4, 3)
+ WORKSPACEKEYS(XK_5, 4)
+ WORKSPACEKEYS(XK_6, 5)
+ WORKSPACEKEYS(XK_7, 6)
+ WORKSPACEKEYS(XK_8, 7)
+ WORKSPACEKEYS(XK_9, 8)
+ WORKSPACEKEYS(XK_0, 9)
+ WORKSPACEKEYS(XK_End, 9)
};
static Button buttons [] =
@@ -32,4 +44,4 @@ static Button buttons [] =
XCB_BUTTON_INDEX_3,
mouseresize,
{ 0 }},
-};
-\ No newline at end of file
+};
diff --git a/kbgwm.c b/kbgwm.c
@@ -15,9 +15,15 @@
static void start(const Arg* arg);
static void mousemove(const Arg* arg);
static void mouseresize(const Arg* arg);
+static void nextWorkspace(const Arg* arg);
+static void previousWorkspace(const Arg* arg);
+static void changeWorkspace(const Arg* arg);
+static void sendToWorkspace(const Arg* arg);
#include "config.h"
+static void onWorkspaceChanged();
+
#define BORDER_WIDTH_X2 (BORDER_WIDTH << 1)
bool quit = false;
@@ -29,6 +35,8 @@ xcb_screen_t* screen;
uint_least16_t previous_x;
uint_least16_t previous_y;
+uint_least8_t currentWorkspace = 0;
+
static window* focusedWindow;
window* windows;
@@ -142,6 +150,9 @@ void handle_maprequest(xcb_map_request_event_t* event)
window->width = geometry->width;
window->height = geometry->height;
+ printf("Setting new window to workspace %d\n", currentWorkspace);
+ window->workspace = currentWorkspace;
+
if (windows != NULL)
{
window->next = windows;
@@ -199,7 +210,7 @@ void handle_buttonrelease(xcb_button_release_event_t* event)
resizing = false;
}
-void mousemove(const Arg* arg)
+void mousemove(__attribute__((unused)) const Arg* arg)
{
printf("mousemove\n");
moving = true;
@@ -212,7 +223,7 @@ void mousemove(const Arg* arg)
xcb_flush(c);
}
-void mouseresize(const Arg* arg)
+void mouseresize(__attribute__((unused)) const Arg* arg)
{
printf("mouseresize\n");
resizing = true;
@@ -336,6 +347,68 @@ void start(const Arg* arg)
}
}
+/*
+ * Workspace
+ */
+
+void nextWorkspace(__attribute__((unused)) const Arg* arg)
+{
+ printf("nextWorkspace\n");
+
+ currentWorkspace = (currentWorkspace + 1) % 10;
+ onWorkspaceChanged();
+}
+
+void previousWorkspace(__attribute__((unused)) const Arg* arg)
+{
+ printf("previousWorkspace\n");
+
+ currentWorkspace = (currentWorkspace + 9) % 10;
+ onWorkspaceChanged();
+}
+
+void changeWorkspace(const Arg* arg)
+{
+ printf("changeWorkspace: arg=%d\n", arg->i);
+
+ currentWorkspace = arg->i;
+ onWorkspaceChanged();
+}
+
+void sendToWorkspace(__attribute__((unused)) const Arg* arg)
+{
+ printf("sendToWorkspace: arg=%d\n", arg->i);
+
+ if (focusedWindow != NULL)
+ {
+ focusedWindow->workspace = arg->i;
+ xcb_unmap_window(c, focusedWindow->id);
+ xcb_flush(c);
+ focusedWindow = NULL;
+ }
+}
+
+void onWorkspaceChanged()
+{
+ printf("onWorkspaceChanged: currentWorkspace=%d\n", currentWorkspace);
+ assert(currentWorkspace <= 9);
+
+ // We currently have no clients
+ if (windows == NULL)
+ return;
+
+ window* window = windows;
+
+ do {
+ if (window->workspace == currentWorkspace)
+ xcb_map_window(c, window->id);
+ else
+ xcb_unmap_window(c, window->id);
+ } while ((window = window->next) != NULL);
+
+ xcb_flush(c);
+}
+
int main(void)
{
/*
@@ -372,9 +445,6 @@ int main(void)
root = screen->root;
- printf("White: %d\n", screen->white_pixel);
- printf("Black: %d\n", screen->black_pixel);
-
xcb_flush(c);
setupEvents();
diff --git a/types.h b/types.h
@@ -3,7 +3,7 @@
typedef union
{
-
+ const uint_least8_t i;
const char** cmd;
}
Arg;
@@ -36,11 +36,10 @@ typedef struct window window;
struct window
{
xcb_window_t id;
- int_least16_t x,
- y;
- uint_least16_t width,
- height;
+ int_least16_t x, y;
+ uint_least16_t width, height;
+ uint_least8_t workspace;
window* next;
};
-#endif /* TYPES_H_ */
-\ No newline at end of file
+#endif /* TYPES_H_ */