update some property identifiers

This commit is contained in:
Akos Horvath 2024-03-07 17:44:41 +01:00
parent 2f6e191b3b
commit b7adb5349e
5 changed files with 33 additions and 59 deletions

View File

@ -71,8 +71,8 @@ Client* wm_client_create(Wm *wm, Window w)
c->next = NULL;
c->prev = NULL;
c->window = w;
c->m = wm->smon;
c->ws = &wm->smon->workspaces[wm->smon->selws];
c->m = wm->selected_monitor;
c->ws = &CURRENT_WS(wm);
c->hidden = true;
c->is_floating = false;
c->name = NULL;
@ -235,7 +235,7 @@ void wm_client_swap_dir(Wm* wm, Client *c, int dir)
wm_treenode_swap(c->ws->tree, client_node, client_node1);
wm_layout(wm, wm->smon);
wm_layout(wm, wm->selected_monitor);
}
void wm_client_free(Wm *wm, Client *c)
@ -399,7 +399,7 @@ ret:
Client* wm_client_get_focused(Wm *wm)
{
Workspace *ws = &wm->smon->workspaces[wm->smon->selws];
Workspace *ws = &CURRENT_WS(wm);
TreeNode *node = wm_treenode_ptr_find_focused_client_node(ws->tree);
if (!node)
@ -440,7 +440,7 @@ void wm_monitor_clients_border(Wm *wm, Monitor *m)
{
DEBUG_PRINT("%s\n", __func__)
RETURN_IF_NULL(m);
NodeArray *clients = wm_treenode_find_client_nodes(m->workspaces[m->selws].tree);
NodeArray *clients = wm_treenode_find_client_nodes(m->workspaces[m->selected_ws].tree);
if (clients->size == 0)
return;

View File

@ -50,7 +50,6 @@ struct Client {
XWindowChanges wm_client_to_xwchanges(Client *c);
Client* wm_client_find(Wm* wm, Window w);
Client *wm_get_last_client(Wm *wm, Monitor m);
Client* wm_client_create(Wm *wm, Window w);
void wm_client_handle_window_types(Wm *wm, Client *c, XMapRequestEvent e);
void wm_client_hide(Wm *wm, Client *c);

View File

@ -207,14 +207,14 @@ UIntArray* wm_nonempty_workspaces_to_strptrarray(Wm *wm)
_Static_assert(sizeof(uint64_t) == sizeof(uint64_t*), "static assert failed");
UIntArray *ret = wm_uintarray_new();
for (size_t i = 0; i < wm->smon->wscount; i++) {
TreeNode *node = wm->smon->workspaces[i].tree;
for (size_t i = 0; i < wm->selected_monitor->wscount; i++) {
TreeNode *node = wm->selected_monitor->workspaces[i].tree;
if (!wm_treenode_is_empty(node) || (node->type == NODE_CLIENT && node->client)) {
WmWorkspaceToStrRet *ws_str_with_index = malloc(sizeof(WmWorkspaceToStrRet));
assert(ws_str_with_index);
*ws_str_with_index = (WmWorkspaceToStrRet) {
.ws_index = i,
.str = wm_treenode_to_str(wm->smon->workspaces[i].tree)
.str = wm_treenode_to_str(wm->selected_monitor->workspaces[i].tree)
};
wm_uintarray_push(ret, (uint64_t)ws_str_with_index);
}

View File

@ -58,7 +58,7 @@ void wm_monitors_open_all(Wm *wm, Display *d)
exit(1);
}
wm->wm_mc = count;
wm->monitors_len = count;
wm->monitors = malloc(count * sizeof(Monitor));
assert(wm->monitors);
@ -68,7 +68,7 @@ void wm_monitors_open_all(Wm *wm, Display *d)
wm->monitors[i].wscount = 9;
wm->monitors[i].workspaces = calloc(wm->monitors[i].wscount, sizeof(Workspace));
assert(wm->monitors[i].workspaces);
wm->monitors[i].selws = 0;
wm->monitors[i].selected_ws = 0;
for (size_t j = 0; j < wm->monitors[i].wscount; j++) {
Workspace *ws = &wm->monitors[i].workspaces[j];
@ -79,12 +79,10 @@ void wm_monitors_open_all(Wm *wm, Display *d)
snprintf(ws->name, WM_WS_NAME_LEN, "%ld", j);
ws->tree = wm_treenode_new(NODE_CLIENT, NULL);
}
wm->monitors[i].clients = NULL;
}
wm->smon = &wm->monitors[0];
DEBUG_PRINT("smon width: %d\n", wm->smon->info.width);
wm->selected_monitor = &wm->monitors[0];
DEBUG_PRINT("smon width: %d\n", wm->selected_monitor->info.width);
XFree(xsi);
}
@ -104,7 +102,7 @@ void wm_set_supported_atoms(Wm *wm)
{
XChangeProperty(wm->display, wm->root.window,
XInternAtom(wm->display, "_NET_NUMBER_OF_DESKTOPS", False), XA_CARDINAL,
32, PropModeReplace, (unsigned char *) &wm->smon->wscount, 1);
32, PropModeReplace, (unsigned char *) &wm->selected_monitor->wscount, 1);
char *desktop_names[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9"};
@ -226,27 +224,27 @@ void wm_ws_tree_insert_client(Wm *wm, Workspace *ws, Client *client)
void wm_switch_ws(Wm *wm, size_t ws)
{
if (ws > wm->smon->wscount)
if (ws > wm->selected_monitor->wscount)
return;
int wscc = 0;
Client *c;
DEBUG_PRINT("switching to ws %ld, clients:", ws);
wm_treenode_print(wm->smon->workspaces[ws].tree);
wm_treenode_print(wm->selected_monitor->workspaces[ws].tree);
NodeArray *current_ws_clients = wm_treenode_find_client_nodes(CURRENT_WS(wm).tree);
for (size_t i = 0; i < current_ws_clients->size; i++) {
c = ((TreeNode**)current_ws_clients->nodes)[i]->client;
assert(c);
if (c->ws->index == wm->smon->selws) {
if (c->ws->index == wm->selected_monitor->selected_ws) {
DEBUG_PRINT("wm_switch_ws hide client selws: %ld\n", c->ws->index)
wm_client_hide(wm, c);
}
}
wm->smon->selws = ws;
wm->selected_monitor->selected_ws = ws;
wm_client_set_atom(wm, &wm-> root, "_NET_CURRENT_DESKTOP",
(unsigned char*) &(ws), XA_CARDINAL, 1);
@ -255,7 +253,7 @@ void wm_switch_ws(Wm *wm, size_t ws)
for (size_t i = 0; i < switch_ws_clients->size; i++) {
c = ((TreeNode**)switch_ws_clients->nodes)[i]->client;
if (c->ws->index == wm->smon->selws) {
if (c->ws->index == wm->selected_monitor->selected_ws) {
wscc++;
wm_client_show(wm, c);
}
@ -266,7 +264,7 @@ void wm_switch_ws(Wm *wm, size_t ws)
if (CURRENT_WS(wm).focused_node)
wm_client_focus(wm, CURRENT_WS(wm).focused_node->client);
wm_layout(wm, wm->smon);
wm_layout(wm, wm->selected_monitor);
wm_nodearray_free(current_ws_clients);
wm_nodearray_free(switch_ws_clients);
@ -274,15 +272,15 @@ void wm_switch_ws(Wm *wm, size_t ws)
void wm_move_client_ws(Wm *wm, int ws)
{
if (ws > wm->smon->wscount)
if (ws > wm->selected_monitor->wscount)
return;
TreeNode *focused_node = wm_treenode_ptr_find_focused_client_node(CURRENT_WS(wm).tree);
Client *moved_client = focused_node->client;
wm_ws_tree_insert_client(wm, &wm->smon->workspaces[ws], moved_client);
wm_ws_tree_insert_client(wm, &wm->selected_monitor->workspaces[ws], moved_client);
wm_client_hide(wm, moved_client);
moved_client->ws = &wm->smon->workspaces[ws];
moved_client->ws = &wm->selected_monitor->workspaces[ws];
wm_client_set_atom(wm, moved_client, "_NET_WM_DESKTOP",
(unsigned char*)&moved_client->ws->index, XA_CARDINAL,
CURRENT_WS(wm).index);
@ -290,9 +288,9 @@ void wm_move_client_ws(Wm *wm, int ws)
wm_treenode_remove_node(wm, CURRENT_WS(wm).tree, focused_node);
CURRENT_WS(wm).focused_node = NULL;
char *str = wm_treenode_to_str(wm->smon->workspaces[ws].tree);
char *str = wm_treenode_to_str(wm->selected_monitor->workspaces[ws].tree);
DEBUG_PRINT("move target ws tree: %s\n", str);
wm_layout(wm, wm->smon);
wm_layout(wm, wm->selected_monitor);
}
void wm_layout(Wm *wm, Monitor *m)
@ -302,7 +300,7 @@ void wm_layout(Wm *wm, Monitor *m)
DEBUG_PRINT("%s\n", __func__);
Workspace *ws = &m->workspaces[m->selws];
Workspace *ws = &m->workspaces[m->selected_ws];
NodeArray *clients = wm_treenode_find_client_nodes(ws->tree);
if (clients->size == 0)
goto ret;
@ -335,20 +333,6 @@ ret:
wm_nodearray_free(clients);
}
Client *wm_get_last_client(Wm *wm, Monitor m)
{
return NULL;
Client *c = m.clients;
if (c == NULL)
return NULL;
while (c->next != NULL)
c = c->next;
return c;
}
void wm_mainloop(Wm *wm)
{
struct sockaddr s;
@ -480,7 +464,7 @@ void wm_exit(Wm *wm)
// TODO: perhaps add created clients to a PtrArray field in workspace.
// would reduce number of calls to wm_treenode_find_client_nodes_ptr
for (size_t i = 0; i < wm->wm_mc; i++) {
for (size_t i = 0; i < wm->monitors_len; i++) {
for (size_t j = 0; j < wm->monitors[i].wscount; j++) {
NodeArray *clients = wm_treenode_find_client_nodes(
wm->monitors[i].workspaces[j].tree);
@ -637,7 +621,7 @@ void wm_kb_switch_split_mode(Wm *wm, Arg *args)
WM_LOG_STATE_START(wm);
wm->smon->workspaces[wm->smon->selws].split = args->i;
wm->selected_monitor->workspaces[wm->selected_monitor->selected_ws].split = args->i;
WM_LOG_STATE_END(wm);
}

View File

@ -63,7 +63,7 @@ if (c == NULL) \
#define WM_WS_NAME_LEN 64
#define CURRENT_WS(wm) (wm)->smon->workspaces[(wm)->smon->selws]
#define CURRENT_WS(wm) (wm)->selected_monitor->workspaces[(wm)->selected_monitor->selected_ws]
#define WM_PREFIX_LEN 4096
@ -99,9 +99,8 @@ typedef enum {
struct Monitor {
Display *display;
XineramaScreenInfo info;
Client *clients;
Workspace *workspaces;
size_t selws;
size_t selected_ws;
size_t wscount;
};
@ -115,27 +114,19 @@ struct Workspace {
};
struct Wm {
// TODO INIT
Display *display;
Monitor *monitors;
Monitor *smon;
bool running;
int wm_mc;
bool other_wm;
size_t monitors_len;
Monitor *selected_monitor;
Client root;
Window dock;
Client *focused_client;
// float cfg_ms_p;
// char *cfg_border_col;
// char *cfg_focused_border_col;
// unsigned char cfg_border_width;
// Keybind *cfg_keybinds;
// int cfg_kb_count;
// bool cfg_focus_on_motion;
Config config;
bool running;
bool log_after_maprequest;
int socket_fd;