void ewmh_update_desktop_names() { char** names = g_new(char*, tag_get_count()); for (int i = 0; i < tag_get_count(); i++) { names[i] = get_tag_by_index(i)->name->str; } XTextProperty text_prop; Xutf8TextListToTextProperty(g_display, names, tag_get_count(), XUTF8StringStyle, &text_prop); XSetTextProperty(g_display, g_root, &text_prop, g_netatom[NetDesktopNames]); XFree(text_prop.value); g_free(names); }
int main() { char key[] = "key1,key2,key3"; char tag[32]; int num = get_tag_num(key,','); // for(int i=0;i<num+1;i++) { get_tag_by_index(key,tag,2); printf("tag %d: %s\n",2,tag); // } return 0; }
int print_tag_status_command(int argc, char** argv, GString* output) { HSMonitor* monitor; if (argc >= 2) { monitor = string_to_monitor(argv[1]); } else { monitor = get_current_monitor(); } if (monitor == NULL) { g_string_append_printf(output, "%s: Monitor \"%s\" not found!\n", argv[0], argv[1]); return HERBST_INVALID_ARGUMENT; } tag_update_flags(); g_string_append_c(output, '\t'); for (int i = 0; i < tag_get_count(); i++) { HSTag* tag = get_tag_by_index(i); // print flags char c = '.'; if (tag->flags & TAG_FLAG_USED) { c = ':'; } HSMonitor *tag_monitor = find_monitor_with_tag(tag); if (tag_monitor == monitor) { c = '+'; if (monitor == get_current_monitor()) { c = '#'; } } else if (tag_monitor) { c = '-'; if (get_current_monitor() == tag_monitor) { c = '%'; } } if (tag->flags & TAG_FLAG_URGENT) { c = '!'; } g_string_append_c(output, c); g_string_append(output, tag->name->str); g_string_append_c(output, '\t'); } return 0; }
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])) { focus_window(me->window, true, true); } break; case NetCurrentDesktop: desktop_index = me->data.l[0]; if (desktop_index < 0 || desktop_index >= g_tags->len) { HSDebug("_NET_CURRENT_DESKTOP: invalid index \"%d\"\n", desktop_index); break; } HSTag* tag = g_array_index(g_tags, HSTag*, 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; } bool new_value[] = { [ _NET_WM_STATE_REMOVE ] = false, [ _NET_WM_STATE_ADD ] = true, [ _NET_WM_STATE_TOGGLE ] = !client_atoms[i].enabled, }; int action = me->data.l[0]; if (action >= LENGTH(new_value)) { HSDebug("_NET_WM_STATE: invalid action %d\n", action); } /* change the value */ client_atoms[i].callback(client, new_value[action]); } break; default: HSDebug("no handler for the client message \"%s\"\n", g_netatom_names[index]); break; } }
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; } }