/** Focused */ static void handle_focus_in(xcb_focus_in_event_t *e) { struct client_t *c; struct workspace_t *ws; NIL_LOG("event: focus in win=%d", e->event); if (e->mode == XCB_NOTIFY_MODE_GRAB || e->mode == XCB_NOTIFY_MODE_UNGRAB || e->detail == XCB_NOTIFY_DETAIL_POINTER) { /* ignore event for grap/ungrap or detail is pointer */ return; } c = find_client(e->event, &ws); if (!c) { NIL_ERR("no client %d", e->event); return; } if (c == ws->focus) { return; } if (ws->focus) { blur_client(ws->focus); } focus_client(c); ws->focus = c; xcb_flush(nil_.con); }
void buttonpress(XEvent* event) { XButtonEvent* be = &(event->xbutton); HSDebug("name is: ButtonPress on sub %lx, win %lx\n", be->subwindow, be->window); if (mouse_binding_find(be->state, be->button)) { mouse_handle_event(event); } else { HSClient* client = get_client_from_window(be->window); if (client) { focus_client(client, false, true); if (*g_raise_on_click) { client_raise(client); } } } XAllowEvents(g_display, ReplayPointer, be->time); }
void enternotify(XEvent* event) { XCrossingEvent *ce = &event->xcrossing; //HSDebug("name is: EnterNotify, focus = %d\n", event->xcrossing.focus); if (!mouse_is_dragging() && *g_focus_follows_mouse && ce->focus == false) { HSClient* c = get_client_from_window(ce->window); HSFrame* target; if (c && c->tag->floating == false && (target = find_frame_with_client(c->tag->frame, c)) && target->content.clients.layout == LAYOUT_MAX && frame_focused_client(target) != c) { // don't allow focus_follows_mouse if another window would be // hidden during that focus change (which only occurs in max layout) } else if (c) { focus_client(c, false, true); } } }
int jumpto_command(int argc, char** argv, GString* output) { if (argc < 2) { return HERBST_NEED_MORE_ARGS; } HSClient* client = NULL; string_to_client(argv[1], &client); if (client) { focus_client(client, true, true); return 0; } else { g_string_append_printf(output, "%s: Could not find client", argv[0]); if (argc > 1) { g_string_append_printf(output, " \"%s\".\n", argv[1]); } else { g_string_append(output, ".\n"); } return HERBST_INVALID_ARGUMENT; } }
/** Mouse entered */ static void handle_enter_notify(xcb_enter_notify_event_t *e) { NIL_LOG("event: enter notify win=%d, child=%d mode=%d", e->event, e->child, e->mode); #if 0 if (e->mode == XCB_NOTIFY_MODE_NORMAL || e->mode == XCB_NOTIFY_MODE_UNGRAB) { struct client_t *c; struct workspace_t *ws; c = find_client(e->event, &ws); if (!c) { NIL_ERR("no client %d", e->event); return; } if (ws->focus) { blur_client(ws->focus); } focus_client(c); ws->focus = c; xcb_flush(nil_.con); } #endif }
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; } }