Compare commits

..

2 Commits

6 changed files with 92 additions and 11 deletions

View File

@@ -31,6 +31,7 @@ add_executable(${APP_NAME}
xcursor.c
xwindow.c
event.c
action.c
)
# use C23

8
src/action.c Normal file
View File

@@ -0,0 +1,8 @@
#include "action.h"
#include "monitor.h"
#include "wm.h"
void select_tag_of_current_monitor(const user_action_arg_t *arg) {
monitor_select_tag(wm.current_monitor, arg->ui);
}

42
src/action.h Normal file
View File

@@ -0,0 +1,42 @@
#pragma once
#include <stdint.h>
#include <xcb/xproto.h>
typedef union user_action_arg_t {
bool b;
int32_t i;
uint32_t ui;
void *ptr;
} user_action_arg_t;
typedef enum click_area_t {
click_none,
click_tag,
} click_area_t;
typedef enum modifier_t {
modifier_none = 0,
modifier_shift = XCB_MOD_MASK_SHIFT,
modifier_control = XCB_MOD_MASK_CONTROL,
modifier_alt = XCB_MOD_MASK_1,
modifier_super = XCB_MOD_MASK_4,
modifier_any = XCB_MOD_MASK_ANY,
} modifier_t;
typedef enum button_index_t {
button_any = XCB_BUTTON_INDEX_ANY,
button_left = XCB_BUTTON_INDEX_1,
button_right = XCB_BUTTON_INDEX_2,
button_middle = XCB_BUTTON_INDEX_3,
} button_index_t;
typedef struct button_t {
click_area_t click_area;
modifier_t modifiers;
button_index_t button;
void (*func)(const user_action_arg_t *arg);
const user_action_arg_t arg;
} button_t;
void select_tag_of_current_monitor(const user_action_arg_t *arg);

View File

@@ -1,6 +1,10 @@
#pragma once
#include <stdint.h>
static const char *font_family = "monospace";
#include "action.h"
static const char *const font_family = "monospace";
static const int font_size = 10;
static const int default_dpi = 144;
@@ -15,3 +19,7 @@ static const char *const tag_bg = "#222222";
static const char *const active_tag_bg = "#005577";
static const char *const tag_color = "#bbbbbb";
static const char *const active_tag_color = "#eeeeee";
static const button_t button_list[] = {
{click_tag, modifier_none, button_left, select_tag_of_current_monitor, {0}},
};

View File

@@ -7,26 +7,47 @@
#include <xcb/xcb_event.h>
#include <xcb/xproto.h>
#include "monitor.h"
#include "action.h"
#include "default_config.h"
#include "types.h"
#include "utils.h"
#include "wm.h"
static void button_press(xcb_button_press_event_t *ev) {
if (ev->event == wm.current_monitor->bar_window) {
if (ev->event_x >= wm.current_monitor->tag_extent.start &&
ev->event_x <= wm.current_monitor->tag_extent.end) {
for (tag_t *tag = wm.current_monitor->tag_list; tag; tag = tag->next) {
if (ev->event_x >= tag->bar_extent.start &&
ev->event_x <= tag->bar_extent.end) {
monitor_select_tag(wm.current_monitor, tag->mask);
break;
click_area_t click_area = click_none;
user_action_arg_t arg = {0};
for (monitor_t *m = wm.monitor_list; m; m = m->next) {
if (ev->event == m->bar_window) {
if (wm.current_monitor != m) wm.current_monitor = m;
if (ev->event_x >= m->tag_extent.start &&
ev->event_x <= m->tag_extent.end) {
click_area = click_tag;
for (tag_t *tag = m->tag_list; tag; tag = tag->next) {
if (ev->event_x >= tag->bar_extent.start &&
ev->event_x <= tag->bar_extent.end) {
arg.ui = tag->mask;
break;
}
}
}
break;
}
}
for (int i = 0; i < countof(button_list); i++) {
if (click_area == button_list[i].click_area &&
button_list[i].button == ev->detail &&
button_list[i].modifiers == ev->state) {
button_list[i].func(&arg);
}
}
}
static void key_press(xcb_key_press_event_t *ev) { printf("key press\n"); }
static void handle_xcb_event(xcb_generic_event_t *event) {
uint8_t event_type = XCB_EVENT_RESPONSE_TYPE(event);
@@ -37,6 +58,7 @@ static void handle_xcb_event(xcb_generic_event_t *event) {
break
EVENT(XCB_BUTTON_PRESS, button_press);
EVENT(XCB_KEY_PRESS, key_press);
#undef EVENT
}

View File

@@ -320,7 +320,7 @@ static void debug_show_monitor_list(void) {
m->name, wm.bar_height);
printf("tag extend: [%d, %d]\n", m->tag_extent.start, m->tag_extent.end);
for (const tag_t *tag = m->tag_list; tag; tag = tag->next) {
printf("tag[%u]: 0b%09b, \"%s\", [%d, %d]\n", tag->index, tag->mask,
printf("tag[%u]: %4u, \"%s\", [%d, %d]\n", tag->index, tag->mask,
tag->name, tag->bar_extent.start, tag->bar_extent.end);
}
}