commit 02240121694046ff7043db702dfb98e0a130e556
parent a33f910b951f6aa6f2ef1d85f89daa5129a4adb1
Author: Kebigon <git@kebigon.xyz>
Date: Tue, 10 Aug 2021 07:41:20 +0900
Make list generic
Diffstat:
5 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/client.c b/client.c
@@ -141,7 +141,7 @@ struct client *client_find_workspace(xcb_window_t id, uint_fast8_t workspace)
{
assert(workspace < workspaces_length);
- struct item *item = list_find(&workspaces[workspace], id);
+ struct item *item = list_find_client(&workspaces[workspace], id);
return item == NULL ? NULL : item->data;
}
@@ -166,7 +166,7 @@ void client_remove_all_workspaces(xcb_window_t id)
for (uint_fast8_t workspace = 0; workspace != workspaces_length; workspace++)
{
- item = list_find(&workspaces[workspace], id);
+ item = list_find_client(&workspaces[workspace], id);
if (item != NULL)
list_remove(&workspaces[workspace], item);
}
@@ -211,7 +211,7 @@ void client_kill(__attribute__((unused)) const union Arg *arg)
if (!xcb_send_atom(item->data, wm_delete_window))
{
// The client does not support WM_DELETE, let's kill it
- xcb_kill_client(c, item->data->id);
+ xcb_kill_client(c, ((struct client *)item->data)->id);
}
xcb_flush(c);
diff --git a/events.c b/events.c
@@ -56,9 +56,9 @@ static void handle_button_press(xcb_generic_event_t *e)
struct item *focused = list_head(&workspaces[current_workspace]);
// The window clicked is not the one in focus, we have to focus it
- if (focused == NULL || window != focused->data->id)
+ if (focused == NULL || window != ((struct client *)focused->data)->id)
{
- struct item *to_focus = list_find(&workspaces[current_workspace], window);
+ struct item *to_focus = list_find_client(&workspaces[current_workspace], window);
assert(to_focus != NULL);
focus_unfocus();
@@ -96,13 +96,13 @@ 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;
- struct item *focused = list_head(&workspaces[current_workspace]);
+ struct item *focused = list_head(&workspaces[current_workspace]);
assert(moving || resizing);
assert(focused != NULL);
- assert(focused->data->id != root);
struct client *client = focused->data;
+ assert(client->id != root);
if (client->maximized)
client_unmaximize(client);
diff --git a/kbgwm.c b/kbgwm.c
@@ -355,7 +355,7 @@ void setup_screen()
void workspace_change(const union Arg *arg)
{
- printf("=======[ user action: focus_next ]=======\n");
+ printf("=======[ user action: workspace_change ]=======\n");
printf("i=%d\n", arg->i);
workspace_set(arg->i);
@@ -407,7 +407,7 @@ void workspace_set(uint_fast8_t new_workspace)
{
do
{
- xcb_unmap_window(c, item->data->id);
+ xcb_unmap_window(c, ((struct client *)item->data)->id);
} while ((item = item->next) != NULL);
}
@@ -416,7 +416,7 @@ void workspace_set(uint_fast8_t new_workspace)
{
do
{
- xcb_map_window(c, item->data->id);
+ xcb_map_window(c, ((struct client *)item->data)->id);
} while ((item = item->next) != NULL);
}
diff --git a/list.c b/list.c
@@ -50,7 +50,7 @@ void list_move_to_head(struct item **list, struct item *item)
}
// Add a client to the head of the list
-void list_add(struct item **list, struct client *e)
+void list_add(struct item **list, void *e)
{
struct item *item = emalloc(sizeof(struct item));
item->data = e;
@@ -64,7 +64,7 @@ void list_add(struct item **list, struct client *e)
}
// Remove an item from the list
-struct client *list_remove(struct item **list, struct item *item)
+void *list_remove(struct item **list, struct item *item)
{
if (list_is_empty(list))
return NULL;
@@ -83,12 +83,12 @@ struct client *list_remove(struct item **list, struct item *item)
}
// Remove the client from the head of the list
-struct client *list_remove_head(struct item **list)
+void *list_remove_head(struct item **list)
{
return list_is_empty(list) ? NULL : list_remove(list, *list);
}
-struct item *list_find(struct item **list, xcb_window_t id)
+struct item *list_find_client(struct item **list, xcb_window_t id)
{
if (list_is_empty(list))
return NULL;
@@ -97,7 +97,7 @@ struct item *list_find(struct item **list, xcb_window_t id)
do
{
- if (item->data->id == id)
+ if (((struct client *)item->data)->id == id)
return item;
} while ((item = item->next) != NULL);
diff --git a/list.h b/list.h
@@ -22,7 +22,7 @@
struct item
{
- struct client *data;
+ void *data;
struct item *previous;
struct item *next;
};
@@ -30,11 +30,11 @@ struct item
struct item *list_tail(struct item **);
void list_move_to_head(struct item **, struct item *);
-void list_add(struct item **, struct client *);
-struct client *list_remove(struct item **, struct item *);
-struct client *list_remove_head(struct item **);
+void list_add(struct item **, void *);
+void *list_remove(struct item **, struct item *);
+void *list_remove_head(struct item **);
-struct item *list_find(struct item **, xcb_window_t);
+struct item *list_find_client(struct item **, xcb_window_t);
// returns true if the list contains no items
// the goal of this function is to make the intent explicit