void unmanage_client(Window win) { HSClient* client = get_client_from_window(win); if (!client) { return; } if (client->dragged) { mouse_stop_drag(); } // remove from tag frame_remove_window(client->tag->frame, win); // ignore events from it XSelectInput(g_display, win, 0); //XUngrabButton(g_display, AnyButton, AnyModifier, win); // permanently remove it HSTag* tag = client->tag; g_hash_table_remove(g_clients, &win); // and arrange monitor after the client has been removed from the stack HSMonitor* m = find_monitor_with_tag(tag); tag_update_focus_layer(tag); if (m) monitor_apply_layout(m); ewmh_remove_client(win); tag_set_flags_dirty(); }
void buttonrelease(XEvent* event) { HSDebug("name is: ButtonRelease\n"); mouse_stop_drag(); }
void ewmh_handle_client_message(XEvent* event) { HSDebug("Received event: ClientMessage\n"); XClientMessageEvent* me = &(event->xclient); int index; for (index = 0; index < NetCOUNT; index++) { if (me->message_type == g_netatom[index]) { break; } } if (index >= NetCOUNT) { HSDebug("received unknown client message\n"); return; } HSClient* client; int desktop_index; switch (index) { case NetActiveWindow: // only steal focus it allowed to the current source // (i.e. me->data.l[0] in this case as specified by EWMH) if (focus_stealing_allowed(me->data.l[0])) { HSClient* client = get_client_from_window(me->window); if (client) { focus_client(client, true, true); } } break; case NetCurrentDesktop: { desktop_index = me->data.l[0]; if (desktop_index < 0 || desktop_index >= tag_get_count()) { HSDebug("_NET_CURRENT_DESKTOP: invalid index \"%d\"\n", desktop_index); break; } HSTag* tag = get_tag_by_index(desktop_index); monitor_set_tag(get_current_monitor(), tag); break; } case NetWmDesktop: { desktop_index = me->data.l[0]; if (!focus_stealing_allowed(me->data.l[1])) { break; } HSTag* target = get_tag_by_index(desktop_index); client = get_client_from_window(me->window); if (client && target) { tag_move_client(client, target); } break; } case NetWmState: { client = get_client_from_window(me->window); /* ignore requests for unmanaged windows */ if (!client || !client->ewmhrequests) break; /* mapping between EWMH atoms and client struct members */ struct { int atom_index; bool enabled; void (*callback)(HSClient*, bool); } client_atoms[] = { { NetWmStateFullscreen, client->fullscreen, client_set_fullscreen }, { NetWmStateDemandsAttention, client->urgent, client_set_urgent }, }; /* me->data.l[1] and [2] describe the properties to alter */ for (int prop = 1; prop <= 2; prop++) { if (me->data.l[prop] == 0) { /* skip if no property is specified */ continue; } /* check if we support the property data[prop] */ int i; for (i = 0; i < LENGTH(client_atoms); i++) { if (g_netatom[client_atoms[i].atom_index] == me->data.l[prop]) { break; } } if (i >= LENGTH(client_atoms)) { /* property will not be handled */ continue; } auto new_value = ArrayInitializer<bool,3>({ { _NET_WM_STATE_REMOVE , false }, { _NET_WM_STATE_ADD , true }, { _NET_WM_STATE_TOGGLE , !client_atoms[i].enabled }, }).a; int action = me->data.l[0]; if (action >= new_value.size()) { HSDebug("_NET_WM_STATE: invalid action %d\n", action); } /* change the value */ client_atoms[i].callback(client, new_value[action]); } break; } case NetWmMoveresize: { client = get_client_from_window(me->window); if (!client) { break; } int direction = me->data.l[2]; if (direction == _NET_WM_MOVERESIZE_MOVE || direction == _NET_WM_MOVERESIZE_MOVE_KEYBOARD) { mouse_initiate_move(client, 0, NULL); } else if (direction == _NET_WM_MOVERESIZE_CANCEL) { if (mouse_is_dragging()) mouse_stop_drag(); } else { // anything else is a resize mouse_initiate_resize(client, 0, NULL); } break; } default: HSDebug("no handler for the client message \"%s\"\n", g_netatom_names[index]); break; } }