Client* manage_client(Window win) { if (get_client_from_window(win)) return NULL; // init client Client* client = create_client(); Monitor* m = get_current_monitor(); // set to window properties client->window = win; client_update_title(client); // apply rules int manage = 1; rules_apply(client, &manage); if (!manage) { destroy_client(client); // map it... just to be sure XMapWindow(gDisplay, win); return NULL; } unsigned int border, depth; Window root_win; int x, y; unsigned int w, h; XGetGeometry(gDisplay, win, &root_win, &x, &y, &w, &h, &border, &depth); // treat wanted coordinates as floating coords XRectangle size = client->float_size; size.width = w; size.height = h; size.x = m->rect.x + m->rect.width/2 - size.width/2; size.y = m->rect.y + m->rect.height/2 - size.height/2 + bar_height; client->float_size = size; client->last_size = size; XMoveResizeWindow(gDisplay, client->window, size.x, size.y, size.width, size.height); // actually manage it g_array_append_val(g_clients, client); XSetWindowBorderWidth(gDisplay, win, window_border_width); // insert to layout if (!client->tag) client->tag = m->tag; // get events from window client_update_wm_hints(client); XSelectInput(gDisplay, win, CLIENT_EVENT_MASK); window_grab_button(win); frame_insert_window(client->tag->frame, win); monitor_apply_layout(find_monitor_with_tag(client->tag)); return client; }
/** * data has been received; initialize/fill in the rest of the cap structure, * figure out how to parse it, hand off to parsers, then hand parsed data to apply_rules() */ static void process_packet(unsigned iface, struct cap *c) { unsigned (*parse)(struct cap *) = NULL; struct tm *tm; /* initialize cap */ c->used = 0; c->pkt_cnt = 1; /* we're using first entry for logical */ memset(c->prots, 0, sizeof c->prots); /* fill in logical frame */ c->pkt[0].pkt = LOGIC; c->pkt[0].type = PKT_NONE; c->pkt[0].len = 0; c->pkt[0].data.logic.frame = Frame++; c->pkt[0].data.logic.len = c->len; c->pkt[0].data.logic.used = 0; tm = localtime(&c->pkt[0].data.logic.header->ts.tv_sec); memcpy(&c->pkt[0].data.logic.tm, tm, sizeof *tm); /* figure out packet's entry parse routine */ switch (Datalink[iface]) { case DLT_EN10MB: /* ethernet */ parse = parse_eth; break; case DLT_LINUX_SLL: parse = parse_linux_sll; break; default: fprintf(stderr, "process_packet(%u, %p) don't know datalink %d\n", iface, (void *)c, Datalink[iface]); break; } { unsigned bytes; bytes = parse(c); if (0 == bytes) { printf("packet not parsed...\n"); return; } else if (bytes < c->len) { /* handle unknown trailing data */ c->pkt[c->pkt_cnt].pkt = UNKNOWN; c->pkt[c->pkt_cnt].len = c->len - bytes; c->pkt[c->pkt_cnt].data.unknown.data = c->raw + c->used; c->pkt[c->pkt_cnt].data.unknown.len = c->len - bytes; c->pkt_cnt++; return; } c->pkt[0].data.logic.used = c->used; rules_apply(c); } }
void create_client(Window win, XWindowAttributes *attr) { struct client *c, *tc; c = client_create(win, attr); tc = find_client_by_trans(mons, win); client_setup(c, selmon, mons, tc); rules_apply(c); client_map_window(c); client_move_resize(c, c->x, c->y, c->w, c->h, true, true); monitor_add_client(c->mon, c); }
static int single_process_pw(struct db_salt *salt, struct db_password *pw, char *rule) { struct list_entry *first, *second; int first_number, second_number; char pair[RULE_WORD_SIZE]; int split; char *key; if (!(first = pw->words->head)) return -1; first_number = 0; do { if ((key = rules_apply(first->data, rule, 0, NULL))) if (ext_filter(key)) if (single_add_key(salt, key, 0)) return 1; if (!salt->list) return 2; if (!pw->binary) return 0; if (++first_number > words_pair_max) continue; if (!CP_isLetter[(unsigned char)first->data[0]]) continue; second_number = 0; second = pw->words->head; do if (first != second) { if ((split = strlen(first->data)) < length) { strnzcpy(pair, first->data, RULE_WORD_SIZE); strnzcat(pair, second->data, RULE_WORD_SIZE); if ((key = rules_apply(pair, rule, split, NULL))) if (ext_filter(key)) if (single_add_key(salt, key, 0)) return 1; if (!salt->list) return 2; if (!pw->binary) return 0; } if (first->data[1]) { pair[0] = first->data[0]; pair[1] = 0; strnzcat(pair, second->data, RULE_WORD_SIZE); if ((key = rules_apply(pair, rule, 1, NULL))) if (ext_filter(key)) if (single_add_key(salt, key, 0)) return 1; if (!salt->list) return 2; if (!pw->binary) return 0; } } while (++second_number <= words_pair_max && (second = second->next)); } while ((first = first->next)); return 0; }
static int single_process_pw(struct db_salt *salt, struct db_password *pw, char *rule) { struct db_keys *keys; struct list_entry *first, *second; int first_number, second_number; char pair[RULE_WORD_SIZE]; int split; char *key; unsigned int c; if (!(first = pw->words->head)) return -1; keys = salt->keys; first_number = 0; do { if ((key = rules_apply(first->data, rule, 0, NULL))) if (ext_filter(key)) if (single_add_key(keys, key)) if (single_process_buffer(salt)) return 1; if (!salt->list) return 2; if (!pw->binary) return 0; if (++first_number > SINGLE_WORDS_PAIR_MAX) continue; c = (unsigned int)first->data[0] | 0x20; if (c < 'a' || c > 'z') continue; second_number = 0; second = pw->words->head; do if (first != second) { if ((split = strlen(first->data)) < length) { strnzcpy(pair, first->data, RULE_WORD_SIZE); strnzcat(pair, second->data, RULE_WORD_SIZE); if ((key = rules_apply(pair, rule, split, NULL))) if (ext_filter(key)) if (single_add_key(keys, key)) if (single_process_buffer(salt)) return 1; if (!salt->list) return 2; if (!pw->binary) return 0; } if (first->data[1]) { pair[0] = first->data[0]; pair[1] = 0; strnzcat(pair, second->data, RULE_WORD_SIZE); if ((key = rules_apply(pair, rule, 1, NULL))) if (ext_filter(key)) if (single_add_key(keys, key)) if (single_process_buffer(salt)) return 1; if (!salt->list) return 2; if (!pw->binary) return 0; } } while (++second_number <= SINGLE_WORDS_PAIR_MAX && (second = second->next)); } while ((first = first->next)); return 0; }
HSClient* manage_client(Window win) { if (is_herbstluft_window(g_display, win)) { // ignore our own window return NULL; } if (get_client_from_window(win)) { return NULL; } // init client HSClient* client = create_client(); client->pid = window_pid(g_display, win); HSMonitor* m = get_current_monitor(); // set to window properties client->window = win; client_update_title(client); unsigned int border, depth; Window root_win; int x, y; unsigned int w, h; XGetGeometry(g_display, win, &root_win, &x, &y, &w, &h, &border, &depth); // treat wanted coordinates as floating coords client->float_size.x = x; client->float_size.y = y; client->float_size.width = w; client->float_size.height = h; // apply rules HSClientChanges changes; client_changes_init(&changes, client); rules_apply(client, &changes); if (changes.tag_name) { client->tag = find_tag(changes.tag_name->str); } if (!changes.manage) { client_changes_free_members(&changes); client_destroy(client); // map it... just to be sure XMapWindow(g_display, win); return NULL; } // actually manage it g_hash_table_insert(g_clients, &(client->window), client); client->window_str = g_string_sized_new(10); g_string_printf(client->window_str, "0x%lx", win); hsobject_link(g_client_object, &client->object, client->window_str->str); // insert to layout if (!client->tag) { client->tag = m->tag; } // get events from window XSelectInput(g_display, win, CLIENT_EVENT_MASK); // insert window to the stack client->slice = slice_create_client(client); stack_insert_slice(client->tag->stack, client->slice); // insert window to the tag frame_insert_window(lookup_frame(client->tag->frame, changes.tree_index->str), win); client_update_wm_hints(client); if (changes.focus) { // give focus to window if wanted // TODO: make this faster! // WARNING: this solution needs O(C + exp(D)) time where W is the count // of clients on this tag and D is the depth of the binary layout tree frame_focus_window(client->tag->frame, win); } HSAttribute attributes[] = { ATTRIBUTE_STRING( "winid", client->window_str, ATTR_READ_ONLY), ATTRIBUTE_STRING( "title", client->title, ATTR_READ_ONLY), ATTRIBUTE_BOOL( "fullscreen", client->fullscreen, client_attr_fullscreen), ATTRIBUTE_BOOL( "pseudotile", client->pseudotile, client_attr_pseudotile), ATTRIBUTE_BOOL( "ewmhrequests", client->ewmhrequests, ATTR_ACCEPT_ALL), ATTRIBUTE_BOOL( "ewmhnotify", client->ewmhnotify, ATTR_ACCEPT_ALL), ATTRIBUTE_BOOL( "sizehints", client->sizehints, ATTR_ACCEPT_ALL), ATTRIBUTE_BOOL( "urgent", client->urgent, client_attr_urgent), ATTRIBUTE_LAST, }; hsobject_set_attributes(&client->object, attributes); ewmh_window_update_tag(client->window, client->tag); tag_set_flags_dirty(); client_set_fullscreen(client, changes.fullscreen); ewmh_update_window_state(client); // add client after setting the correct tag for the new client // this ensures a panel can read the tag property correctly at this point ewmh_add_client(client->window); HSMonitor* monitor = find_monitor_with_tag(client->tag); if (monitor) { if (monitor != get_current_monitor() && changes.focus && changes.switchtag) { monitor_set_tag(get_current_monitor(), client->tag); } // TODO: monitor_apply_layout() maybe is called twice here if it // already is called by monitor_set_tag() monitor_apply_layout(monitor); } else { if (changes.focus && changes.switchtag) { monitor_set_tag(get_current_monitor(), client->tag); } } client_changes_free_members(&changes); grab_client_buttons(client, false); return client; }