commit 735b48258cc770d6bbe9177deeaa064c200e6fa0
parent 4f83c1a4ff9c288fc5188c85cfcaf75d644e6ab0
Author: Kebigon <git@kebigon.xyz>
Date: Thu, 12 Aug 2021 10:54:01 +0900
Fixes alt+tab only being able to focus the two first clients in a workspace
Diffstat:
5 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/client.h b/client.h
@@ -46,3 +46,4 @@ void client_sanitize_dimensions(struct client *);
void client_remove_all_workspaces(xcb_window_t);
struct client *client_find_all_workspaces(xcb_window_t);
struct client *client_find_workspace(xcb_window_t, uint_fast8_t);
+void client_update_monitor(struct client *);
diff --git a/events.c b/events.c
@@ -92,7 +92,10 @@ static void handle_button_release(__attribute__((unused)) xcb_generic_event_t *e
moving = false;
resizing = false;
- client_update_monitor(list_head(&workspaces[current_workspace]));
+
+ struct item *focused = list_head(&workspaces[current_workspace]);
+ if (focused != NULL)
+ client_update_monitor(focused->data);
}
static void handle_motion_notify(xcb_generic_event_t *e)
diff --git a/kbgwm.c b/kbgwm.c
@@ -135,18 +135,20 @@ void focus_apply()
void focus_next(const union Arg *arg)
{
LOG_DEBUG("=======[ user action: focus_next ]=======");
+ struct item **workspace = &workspaces[current_workspace];
// No clients in the current workspace list
// Only one client in the current workspace list
- if (list_is_empty(&workspaces[current_workspace]) ||
- list_head(&workspaces[current_workspace])->next == NULL)
+ if (list_is_empty(workspace) || list_head(workspace)->next == NULL)
return; // Nothing to be done
- struct item *new_focus = arg->b ? list_tail(&workspaces[current_workspace])
- : list_head(&workspaces[current_workspace])->next;
-
focus_unfocus();
- list_move_to_head(&workspaces[current_workspace], new_focus);
+
+ if (arg->b)
+ list_move_to_head(workspace, list_tail(workspace));
+ else
+ list_move_to_tail(workspace, list_head(workspace));
+
focus_apply();
}
diff --git a/list.c b/list.c
@@ -22,6 +22,17 @@
#include "xcbutils.h"
+// Internal use only
+void list_remove_item(struct item **list, struct item *item)
+{
+ if (item->previous != NULL)
+ item->previous->next = item->next;
+ if (item->next != NULL)
+ item->next->previous = item->previous;
+ if (item == *list)
+ *list = item->next;
+}
+
struct item *list_tail(struct item **list)
{
if (list_is_empty(list))
@@ -38,10 +49,7 @@ void list_move_to_head(struct item **list, struct item *item)
if (list_is_empty(list))
return;
- if (item->previous != NULL)
- item->previous->next = item->next;
- if (item->next != NULL)
- item->next->previous = item->previous;
+ list_remove_item(list, item);
item->previous = NULL;
item->next = *list;
@@ -49,6 +57,19 @@ void list_move_to_head(struct item **list, struct item *item)
*list = item;
}
+void list_move_to_tail(struct item **list, struct item *item)
+{
+ struct item *tail = list_tail(list);
+ if (tail == NULL)
+ return;
+
+ list_remove_item(list, item);
+
+ item->next = NULL;
+ tail->next = item;
+ item->previous = tail;
+}
+
// Add a client to the head of the list
void list_add(struct item **list, void *e)
{
@@ -69,15 +90,9 @@ void *list_remove(struct item **list, struct item *item)
if (list_is_empty(list))
return NULL;
- struct client *data = item->data;
-
- if (item->previous != NULL)
- item->previous->next = item->next;
- if (item->next != NULL)
- item->next->previous = item->previous;
- if (item == *list)
- *list = item->next;
+ list_remove_item(list, item);
+ struct client *data = item->data;
free(item);
return data;
}
diff --git a/list.h b/list.h
@@ -29,6 +29,7 @@ struct item
struct item *list_tail(struct item **);
void list_move_to_head(struct item **, struct item *);
+void list_move_to_tail(struct item **, struct item *);
void list_add(struct item **, void *);
void *list_remove(struct item **, struct item *);