kbgwm

sucklessy floating window manager
git clone https://git.neuralcrash.com/kbgwm.git
Log | Files | Refs | README | LICENSE

commit 84dfbc2d7dcea9e59d1f9adb51a4f25845a7ebad
parent ca46f35e356a590e8f7d5147d81b1b7e5bf94d2c
Author: Kebigon <git@kebigon.xyz>
Date:   Mon,  9 Aug 2021 13:39:03 +0900

Remove typedefs

Diffstat:
Mclient.c | 42+++++++++++++++++++++---------------------
Mclient.h | 33++++++++++++++++-----------------
Mconfig.h | 4++--
Mevents.c | 8++++----
Mkbgwm.c | 32++++++++++++++++----------------
Mkbgwm.h | 24++++++++++++------------
Mtypes.h | 20++++++++++----------
Mxcbutils.c | 4++--
Mxcbutils.h | 4++--
9 files changed, 85 insertions(+), 86 deletions(-)

diff --git a/client.c b/client.c @@ -45,13 +45,13 @@ static inline uint16_t uint16_in_range(uint16_t value, uint16_t min, uint16_t ma } // Add a client to the current workspace list -void client_add(client *client) +void client_add(struct client *client) { client_add_workspace(client, current_workspace); } // Add a client to a workspace list -void client_add_workspace(client *client, uint_fast8_t workspace) +void client_add_workspace(struct client *client, uint_fast8_t workspace) { assert(client != NULL); assert(workspace < workspaces_length); @@ -84,7 +84,7 @@ void client_create(xcb_window_t id) xcb_icccm_get_wm_normal_hints_reply(c, xcb_icccm_get_wm_normal_hints_unchecked(c, id), &hints, NULL); - client *new_client = emalloc(sizeof(client)); + struct client *new_client = emalloc(sizeof(struct client)); new_client->id = id; new_client->maximized = false; @@ -132,16 +132,16 @@ void client_create(xcb_window_t id) } // Find a client in the current workspace list -client *client_find(xcb_window_t id) +struct client *client_find(xcb_window_t id) { return client_find_workspace(id, current_workspace); } -client *client_find_all_workspaces(xcb_window_t id) +struct client *client_find_all_workspaces(xcb_window_t id) { for (uint_fast8_t workspace = 0; workspace != workspaces_length; workspace++) { - client *client = client_find_workspace(id, workspace); + struct client *client = client_find_workspace(id, workspace); if (client != NULL) return client; } @@ -149,11 +149,11 @@ client *client_find_all_workspaces(xcb_window_t id) return NULL; } -client *client_find_workspace(xcb_window_t id, uint_fast8_t workspace) +struct client *client_find_workspace(xcb_window_t id, uint_fast8_t workspace) { assert(workspace < workspaces_length); - client *client = workspaces[workspace]; + struct client *client = workspaces[workspace]; if (client != NULL) do @@ -166,18 +166,18 @@ client *client_find_workspace(xcb_window_t id, uint_fast8_t workspace) } // Remove the focused client from the current workspace list -client *client_remove() +struct client *client_remove() { return client_remove_workspace(current_workspace); } // Remove the focused client from a workspace list -client *client_remove_workspace(uint_fast8_t workspace) +struct client *client_remove_workspace(uint_fast8_t workspace) { assert(workspace < workspaces_length); assert(workspaces[workspace] != NULL); - client *client = workspaces[workspace]; + struct client *client = workspaces[workspace]; if (client->next == client) workspaces[workspace] = NULL; else @@ -194,7 +194,7 @@ void client_remove_all_workspaces(xcb_window_t id) { for (uint_fast8_t workspace = 0; workspace != workspaces_length; workspace++) { - client *client = client_find_workspace(id, workspace); + struct client *client = client_find_workspace(id, workspace); if (client != NULL) { if (client->next == client) @@ -211,7 +211,7 @@ void client_remove_all_workspaces(xcb_window_t id) } } -void client_sanitize_position(client *client) +void client_sanitize_position(struct client *client) { int16_t x = int16_in_range(client->x, 0, screen->width_in_pixels - client->width - border_width_x2); @@ -224,7 +224,7 @@ void client_sanitize_position(client *client) client->y = y; } -void client_sanitize_dimensions(client *client) +void client_sanitize_dimensions(struct client *client) { uint16_t width = uint16_in_range(client->width, client->min_width, client->max_width); width = uint16_in_range(width, 0, screen->width_in_pixels - client->x - border_width_x2); @@ -237,7 +237,7 @@ void client_sanitize_dimensions(client *client) client->height = height; } -void client_kill(__attribute__((unused)) const Arg *arg) +void client_kill(__attribute__((unused)) const union Arg *arg) { printf("=======[ user action: client_kill ]=======\n"); @@ -254,7 +254,7 @@ void client_kill(__attribute__((unused)) const Arg *arg) xcb_flush(c); } -void client_toggle_maximize(__attribute__((unused)) const Arg *arg) +void client_toggle_maximize(__attribute__((unused)) const union Arg *arg) { printf("=======[ user action: client_toggle_maximize ]=======\n"); @@ -262,7 +262,7 @@ void client_toggle_maximize(__attribute__((unused)) const Arg *arg) if (workspaces[current_workspace] == NULL) return; // Nothing to be done - client *client = workspaces[current_workspace]; + struct client *client = workspaces[current_workspace]; if (client->maximized) client_unmaximize(client); @@ -272,7 +272,7 @@ void client_toggle_maximize(__attribute__((unused)) const Arg *arg) xcb_flush(c); } -void client_maximize(client *client) +void client_maximize(struct client *client) { assert(client != NULL); assert(!client->maximized); @@ -286,7 +286,7 @@ void client_maximize(client *client) values); } -void client_unmaximize(client *client) +void client_unmaximize(struct client *client) { assert(client != NULL); assert(client->maximized); @@ -300,7 +300,7 @@ void client_unmaximize(client *client) values); } -void client_grab_buttons(client *client, bool focused) +void client_grab_buttons(struct client *client, bool focused) { xcb_ungrab_button(c, XCB_BUTTON_INDEX_ANY, client->id, XCB_MOD_MASK_ANY); @@ -319,7 +319,7 @@ void client_grab_buttons(client *client, bool focused) { uint16_t modifiers[] = {0, numlockmask, XCB_MOD_MASK_LOCK, numlockmask | XCB_MOD_MASK_LOCK}; - Button button = buttons[i]; + struct Button button = buttons[i]; for (uint_fast8_t j = 0; j != LENGTH(modifiers); j++) { diff --git a/client.h b/client.h @@ -20,8 +20,7 @@ #include "types.h" #include <stdbool.h> -typedef struct client_t client; -struct client_t +struct client { xcb_window_t id; int16_t x, y; @@ -29,22 +28,22 @@ struct client_t int32_t min_width, min_height; int32_t max_width, max_height; bool maximized; - client *previous; - client *next; + struct client *previous; + struct client *next; }; -void client_grab_buttons(client *, bool); -void client_kill(const Arg *); +void client_grab_buttons(struct client *, bool); +void client_kill(const union Arg *); void client_create(xcb_window_t); -void client_toggle_maximize(const Arg *); -client *client_remove(); -void client_add_workspace(client *, uint_fast8_t); -client *client_remove_workspace(uint_fast8_t); -client *client_find(xcb_window_t); -void client_maximize(client *); -void client_unmaximize(client *); -void client_sanitize_position(client *); -void client_sanitize_dimensions(client *); +void client_toggle_maximize(const union Arg *); +struct client *client_remove(); +void client_add_workspace(struct client *, uint_fast8_t); +struct client *client_remove_workspace(uint_fast8_t); +struct client *client_find(xcb_window_t); +void client_maximize(struct client *); +void client_unmaximize(struct client *); +void client_sanitize_position(struct client *); +void client_sanitize_dimensions(struct client *); void client_remove_all_workspaces(xcb_window_t); -client *client_find_all_workspaces(xcb_window_t); -client *client_find_workspace(xcb_window_t, uint_fast8_t); +struct client *client_find_all_workspaces(xcb_window_t); +struct client *client_find_workspace(xcb_window_t, uint_fast8_t); diff --git a/config.h b/config.h @@ -43,7 +43,7 @@ static const char *menucmd[] = {"dmenu_run", NULL}; { MODKEY|XCB_MOD_MASK_SHIFT, KEY, workspace_send, {.i = WORKSPACE} }, \ { MODKEY, KEY, workspace_change, {.i = WORKSPACE} }, -const Key keys[] = { +const struct Key keys[] = { { MODKEY, XK_Return, start, { .cmd = termcmd } }, { MODKEY, XK_p, start, { .cmd = menucmd } }, { MODKEY, XK_Page_Up, workspace_previous, { 0 } }, @@ -67,7 +67,7 @@ const Key keys[] = { WORKSPACEKEYS(XK_End, 9) }; -const Button buttons[] = { +const struct Button buttons[] = { { MODKEY, XCB_BUTTON_INDEX_1, mousemove, { 0 } }, { MODKEY, XCB_BUTTON_INDEX_3, mouseresize, { 0 } }, }; diff --git a/events.c b/events.c @@ -56,7 +56,7 @@ static void handle_button_press(xcb_generic_event_t *e) // The window clicked is not the one in focus, we have to focus it if (workspaces[current_workspace] == NULL || window != workspaces[current_workspace]->id) { - client *client = client_find(window); + struct client *client = client_find(window); assert(client != NULL); focus_unfocus(); @@ -94,7 +94,7 @@ static void handle_button_release(__attribute__((unused)) xcb_generic_event_t *e static void handle_motion_notify(xcb_generic_event_t *e) { xcb_motion_notify_event_t *event = (xcb_motion_notify_event_t *)e; - client *client = workspaces[current_workspace]; + struct client *client = workspaces[current_workspace]; assert(moving || resizing); assert(client != NULL); @@ -143,7 +143,7 @@ static void handle_destroy_notify(xcb_generic_event_t *e) static void handle_unmap_notify(xcb_generic_event_t *e) { xcb_unmap_notify_event_t *event = (xcb_unmap_notify_event_t *)e; - client *client = client_find_all_workspaces(event->window); + struct client *client = client_find_all_workspaces(event->window); // We don't know this client if (client == NULL) @@ -169,7 +169,7 @@ static void handle_map_request(xcb_generic_event_t *e) static void handle_configure_request(xcb_generic_event_t *e) { xcb_configure_request_event_t *event = (xcb_configure_request_event_t *)e; - client *client = client_find_all_workspaces(event->window); + struct client *client = client_find_all_workspaces(event->window); if (client != NULL) { diff --git a/kbgwm.c b/kbgwm.c @@ -44,7 +44,7 @@ xcb_atom_t wm_protocols; xcb_atom_t wm_delete_window; uint_fast8_t current_workspace = 0; -client *workspaces[NB_WORKSPACES]; +struct client *workspaces[NB_WORKSPACES]; static inline void debug_print_globals() { @@ -56,7 +56,7 @@ static inline void debug_print_globals() printf("%d\tNULL\n", workspace); else { - client *client = workspaces[workspace]; + struct client *client = workspaces[workspace]; do { printf("%d\tid=%d x=%d y=%d width=%d height=%d min_width=%d min_height=%d " @@ -155,7 +155,7 @@ static void debug_print_event(xcb_generic_event_t *event) } } -void mousemove(__attribute__((unused)) const Arg *arg) +void mousemove(__attribute__((unused)) const union Arg *arg) { printf("=======[ user action: mousemove ]=======\n"); moving = true; @@ -166,7 +166,7 @@ void mousemove(__attribute__((unused)) const Arg *arg) xcb_flush(c); } -void mouseresize(__attribute__((unused)) const Arg *arg) +void mouseresize(__attribute__((unused)) const union Arg *arg) { printf("=======[ user action: mouseresize ]=======\n"); resizing = true; @@ -191,7 +191,7 @@ void eventLoop() } } -void start(const Arg *arg) +void start(const union Arg *arg) { printf("=======[ user action: start ]=======\n"); printf("cmd %s\n", arg->cmd[0]); @@ -236,7 +236,7 @@ void focus_apply() // Focus the next client in the current workspace list // arg->b : reverse mode -void focus_next(const Arg *arg) +void focus_next(const union Arg *arg) { printf("=======[ user action: focus_next ]=======\n"); @@ -246,7 +246,7 @@ void focus_next(const Arg *arg) workspaces[current_workspace]->next == workspaces[current_workspace]) return; // Nothing to be done - client *new_focus = + struct client *new_focus = arg->b ? workspaces[current_workspace]->previous : workspaces[current_workspace]->next; focus_unfocus(); @@ -257,7 +257,7 @@ void focus_next(const Arg *arg) // Remove the focus from the current client void focus_unfocus() { - client *client = workspaces[current_workspace]; + struct client *client = workspaces[current_workspace]; // No client are focused if (client == NULL) @@ -273,7 +273,7 @@ void focus_unfocus() * Handling events from the event loop */ -void quit(__attribute__((unused)) const Arg *arg) +void quit(__attribute__((unused)) const union Arg *arg) { printf("=======[ user action: quit ]=======\n"); running = false; @@ -345,7 +345,7 @@ void setup_screen() * Workspaces */ -void workspace_change(const Arg *arg) +void workspace_change(const union Arg *arg) { printf("=======[ user action: focus_next ]=======\n"); printf("i=%d\n", arg->i); @@ -353,20 +353,20 @@ void workspace_change(const Arg *arg) workspace_set(arg->i); } -void workspace_next(__attribute__((unused)) const Arg *arg) +void workspace_next(__attribute__((unused)) const union Arg *arg) { printf("=======[ user action: workspace_next ]=======\n"); workspace_set(current_workspace + 1 == workspaces_length ? 0 : current_workspace + 1); } -void workspace_previous(__attribute__((unused)) const Arg *arg) +void workspace_previous(__attribute__((unused)) const union Arg *arg) { printf("=======[ user action: workspace_previous ]=======\n"); workspace_set(current_workspace == 0 ? workspaces_length - 1 : current_workspace - 1); } -void workspace_send(const Arg *arg) +void workspace_send(const union Arg *arg) { printf("=======[ user action: workspace_send ]=======\n"); printf("i=%d\n", arg->i); @@ -377,7 +377,7 @@ void workspace_send(const Arg *arg) if (current_workspace == new_workspace || workspaces[current_workspace] == NULL) return; // Nothing to be done - client *client = client_remove(); + struct client *client = client_remove(); client_add_workspace(client, new_workspace); xcb_unmap_window(c, client->id); @@ -393,7 +393,7 @@ void workspace_set(uint_fast8_t new_workspace) return; // Nothing to be done // Unmap the clients of the current workspace (if any) - client *client = workspaces[current_workspace]; + struct client *client = workspaces[current_workspace]; if (client != NULL) do { @@ -479,7 +479,7 @@ int main(void) { while (workspaces[i] != NULL) { - client *client = client_remove_workspace(i); + struct client *client = client_remove_workspace(i); free(client); } } diff --git a/kbgwm.h b/kbgwm.h @@ -21,18 +21,18 @@ #include "types.h" #include <stdbool.h> -void start(const Arg *arg); -void mousemove(const Arg *arg); -void mouseresize(const Arg *arg); +void start(const union Arg *arg); +void mousemove(const union Arg *arg); +void mouseresize(const union Arg *arg); void focus_apply(); -void focus_next(const Arg *); +void focus_next(const union Arg *); void focus_unfocus(); -void quit(const Arg *); -void workspace_change(const Arg *); -void workspace_next(const Arg *); -void workspace_previous(const Arg *); -void workspace_send(const Arg *); +void quit(const union Arg *); +void workspace_change(const union Arg *); +void workspace_next(const union Arg *); +void workspace_previous(const union Arg *); +void workspace_send(const union Arg *); void workspace_set(uint_fast8_t); #define focused_client workspaces[current_workspace] @@ -49,10 +49,10 @@ extern uint16_t numlockmask; extern xcb_atom_t wm_protocols; extern xcb_atom_t wm_delete_window; extern uint_fast8_t current_workspace; -extern client *workspaces[]; +extern struct client *workspaces[]; -extern const Key keys[]; -extern const Button buttons[]; +extern const struct Key keys[]; +extern const struct Button buttons[]; extern const uint_least8_t keys_length; extern const uint_least8_t buttons_length; diff --git a/types.h b/types.h @@ -21,24 +21,24 @@ #include <stdint.h> #include <xcb/xproto.h> -typedef union { +union Arg { const bool b; const uint_least8_t i; const char **cmd; -} Arg; +}; -typedef struct +struct Key { uint16_t modifiers; xcb_keysym_t keysym; - void (*func)(const Arg *); - const Arg arg; -} Key; + void (*func)(const union Arg *); + const union Arg arg; +}; -typedef struct +struct Button { uint16_t modifiers; xcb_button_t keysym; - void (*func)(const Arg *); - const Arg arg; -} Button; + void (*func)(const union Arg *); + const union Arg arg; +}; diff --git a/xcbutils.c b/xcbutils.c @@ -48,7 +48,7 @@ void *emalloc(size_t size) * */ -void xcb_register_key_events(Key key) +void xcb_register_key_events(struct Key key) { xcb_keycode_t *keycodes; xcb_keycode_t keycode; @@ -129,7 +129,7 @@ xcb_atom_t xcb_get_atom(const char *atom_name) return atom; } -bool xcb_send_atom(client *client, xcb_atom_t atom) +bool xcb_send_atom(struct client *client, xcb_atom_t atom) { assert(client != NULL); diff --git a/xcbutils.h b/xcbutils.h @@ -32,7 +32,7 @@ void *emalloc(size_t size); /* * registering events */ -void xcb_register_key_events(Key key); +void xcb_register_key_events(struct Key key); xcb_keycode_t *xcb_get_keycodes(xcb_keysym_t); xcb_keysym_t xcb_get_keysym(xcb_keycode_t); @@ -45,4 +45,4 @@ xcb_keysym_t xcb_get_keysym(xcb_keycode_t); #define WM_PROTOCOLS "WM_PROTOCOLS" xcb_atom_t xcb_get_atom(const char *); -bool xcb_send_atom(client *, xcb_atom_t); +bool xcb_send_atom(struct client *, xcb_atom_t);