mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-06-19 14:33:16 -04:00
opt: optimzie code struce
This commit is contained in:
parent
3ed650f2e6
commit
5849b6eaff
2 changed files with 36 additions and 45 deletions
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
typedef struct Monitor Monitor;
|
typedef struct Monitor Monitor;
|
||||||
|
|
||||||
/* Double use: as config in config/rcxml.c and as instance in workspaces.c */
|
|
||||||
struct workspace {
|
struct workspace {
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
|
|
||||||
|
|
@ -22,24 +21,16 @@ struct workspace {
|
||||||
} on_ext;
|
} on_ext;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Workspaces */
|
|
||||||
struct dwl_ext_workspace_manager *ext_manager;
|
struct dwl_ext_workspace_manager *ext_manager;
|
||||||
struct wl_list workspaces; /* struct workspace.link */
|
struct wl_list workspaces; /* struct workspace.link */
|
||||||
|
|
||||||
/*
|
|
||||||
* update_focus should normally be set to true. It is set to false only
|
|
||||||
* when this function is called from desktop_focus_view(), in order to
|
|
||||||
* avoid unnecessary extra focus changes and possible recursion.
|
|
||||||
*/
|
|
||||||
void workspaces_switch_to(struct workspace *target) {
|
void workspaces_switch_to(struct workspace *target) {
|
||||||
if (target == target->m->workspace_current) {
|
if (target == target->m->workspace_current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable the old workspace */
|
|
||||||
wlr_scene_node_set_enabled(&target->m->workspace_current->tree->node,
|
wlr_scene_node_set_enabled(&target->m->workspace_current->tree->node,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
dwl_ext_workspace_set_active(target->m->workspace_current->ext_workspace,
|
dwl_ext_workspace_set_active(target->m->workspace_current->ext_workspace,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
|
@ -52,15 +43,9 @@ void workspaces_switch_to(struct workspace *target) {
|
||||||
view(&(Arg){.ui = tag}, true);
|
view(&(Arg){.ui = tag}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable the new workspace */
|
|
||||||
wlr_scene_node_set_enabled(&target->tree->node, true);
|
wlr_scene_node_set_enabled(&target->tree->node, true);
|
||||||
|
|
||||||
/* Save the last visited workspace */
|
|
||||||
target->m->workspace_last = target->m->workspace_current;
|
target->m->workspace_last = target->m->workspace_current;
|
||||||
|
|
||||||
/* Make sure new views will spawn on the new workspace */
|
|
||||||
target->m->workspace_current = target;
|
target->m->workspace_current = target;
|
||||||
|
|
||||||
dwl_ext_workspace_set_active(target->ext_workspace, true);
|
dwl_ext_workspace_set_active(target->ext_workspace, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +104,6 @@ static void add_workspace(int tag, Monitor *m) {
|
||||||
|
|
||||||
bool active = m->workspace_current == workspace;
|
bool active = m->workspace_current == workspace;
|
||||||
|
|
||||||
/* ext */
|
|
||||||
workspace->ext_workspace =
|
workspace->ext_workspace =
|
||||||
dwl_ext_workspace_create(ext_manager, /*id*/ NULL);
|
dwl_ext_workspace_create(ext_manager, /*id*/ NULL);
|
||||||
dwl_ext_workspace_assign_to_group(workspace->ext_workspace, m->ext_group);
|
dwl_ext_workspace_assign_to_group(workspace->ext_workspace, m->ext_group);
|
||||||
|
|
|
||||||
51
src/maomao.c
51
src/maomao.c
|
|
@ -5089,36 +5089,33 @@ void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
|
||||||
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
|
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printstatus(void) {
|
bool tag_has_clients(unsigned int tag) {
|
||||||
Monitor *m;
|
|
||||||
unsigned int current_tag;
|
|
||||||
struct workspace *w;
|
|
||||||
Client *c;
|
Client *c;
|
||||||
bool has_clients = false;
|
bool has_clients = false;
|
||||||
bool is_active = false;
|
|
||||||
|
|
||||||
wl_list_for_each(m, &mons, link) {
|
|
||||||
if (!m->wlr_output->enabled) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current tag for this monitor
|
|
||||||
current_tag = get_tags_first_tag_num(m->tagset[m->seltags]);
|
|
||||||
// Update workspace active states
|
|
||||||
if (workspaces.next != &workspaces) { // If workspaces list is not empty
|
|
||||||
wl_list_for_each(w, &workspaces, link) {
|
|
||||||
if (w && w->m == m) {
|
|
||||||
is_active = (w->tag == current_tag) && !m->isoverview;
|
|
||||||
has_clients = false;
|
|
||||||
wl_list_for_each(c, &clients, link) {
|
wl_list_for_each(c, &clients, link) {
|
||||||
if (c->tags & 1 << (w->tag - 1) & TAGMASK) {
|
if (c->tags & 1 << (tag - 1) & TAGMASK) {
|
||||||
has_clients = true;
|
has_clients = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return has_clients;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dwl_ext_workspace_printstatus(Monitor *m) {
|
||||||
|
unsigned int current_tag;
|
||||||
|
struct workspace *w;
|
||||||
|
bool has_clients = false;
|
||||||
|
bool is_active = false;
|
||||||
|
|
||||||
|
current_tag = get_tags_first_tag_num(m->tagset[m->seltags]);
|
||||||
|
|
||||||
|
wl_list_for_each(w, &workspaces, link) {
|
||||||
|
if (w && w->m == m) {
|
||||||
|
is_active = (w->tag == current_tag) && !m->isoverview;
|
||||||
|
has_clients = tag_has_clients(w->tag);
|
||||||
if (is_active) {
|
if (is_active) {
|
||||||
dwl_ext_workspace_set_active(w->ext_workspace,
|
dwl_ext_workspace_set_hidden(w->ext_workspace, false);
|
||||||
is_active);
|
dwl_ext_workspace_set_active(w->ext_workspace, true);
|
||||||
} else if (has_clients) {
|
} else if (has_clients) {
|
||||||
dwl_ext_workspace_set_hidden(w->ext_workspace, false);
|
dwl_ext_workspace_set_hidden(w->ext_workspace, false);
|
||||||
dwl_ext_workspace_set_active(w->ext_workspace, false);
|
dwl_ext_workspace_set_active(w->ext_workspace, false);
|
||||||
|
|
@ -5130,6 +5127,16 @@ void printstatus(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printstatus(void) {
|
||||||
|
Monitor *m;
|
||||||
|
wl_list_for_each(m, &mons, link) {
|
||||||
|
if (!m->wlr_output->enabled) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update workspace active states
|
||||||
|
dwl_ext_workspace_printstatus(m);
|
||||||
|
|
||||||
// Update IPC output status
|
// Update IPC output status
|
||||||
dwl_ipc_output_printstatus(m);
|
dwl_ipc_output_printstatus(m);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue