Codebase list herbstluftwm / e2147f7
Refactor: Save client pointers in frames Instead of a window buf, the frame has a buf of HSClient-pointers. This reduces the use of get_client_from_window() and makes things more general, which will be needed for decorations. Thorsten Wißmann 10 years ago
7 changed file(s) with 129 addition(s) and 135 deletion(s). Raw diff Collapse all Expand all
210210 client->slice = slice_create_client(client);
211211 stack_insert_slice(client->tag->stack, client->slice);
212212 // insert window to the tag
213 frame_insert_window(lookup_frame(client->tag->frame, changes.tree_index->str), win);
213 frame_insert_client(lookup_frame(client->tag->frame, changes.tree_index->str), client);
214214 client_update_wm_hints(client);
215215 if (changes.focus) {
216216 // give focus to window if wanted
217217 // TODO: make this faster!
218218 // WARNING: this solution needs O(C + exp(D)) time where W is the count
219219 // of clients on this tag and D is the depth of the binary layout tree
220 frame_focus_window(client->tag->frame, win);
220 frame_focus_client(client->tag->frame, client);
221221 }
222222
223223 HSAttribute attributes[] = {
271271 mouse_stop_drag();
272272 }
273273 // remove from tag
274 frame_remove_window(client->tag->frame, win);
274 frame_remove_client(client->tag->frame, client);
275275 // ignore events from it
276276 XSelectInput(g_display, win, 0);
277277 //XUngrabButton(g_display, AnyButton, AnyModifier, win);
367367
368368 lastfocus = window;
369369 /* do some specials for the max layout */
370 bool is_max_layout = frame_focused_window(g_cur_frame) == window
370 bool is_max_layout = frame_focused_client(g_cur_frame) == client
371371 && g_cur_frame->content.clients.layout == LAYOUT_MAX
372372 && get_current_monitor()->tag->floating == false;
373373 if (*g_raise_on_focus || is_max_layout) {
572572 XEvent ev;
573573 // if there is no focus, then there is nothing to do
574574 if (!g_cur_frame) return 0;
575 Window win = frame_focused_window(g_cur_frame);
576 if (!win) return 0;
575 HSClient* client = frame_focused_client(g_cur_frame);
576 if (!client) return 0;
577577 ev.type = ClientMessage;
578 ev.xclient.window = win;
578 ev.xclient.window = client->window;
579579 ev.xclient.message_type = g_wmatom[WMProtocols];
580580 ev.xclient.format = 32;
581581 ev.xclient.data.l[0] = g_wmatom[WMDelete];
582582 ev.xclient.data.l[1] = CurrentTime;
583 XSendEvent(g_display, win, False, NoEventMask, &ev);
583 XSendEvent(g_display, client->window, False, NoEventMask, &ev);
584584 return 0;
585585 }
586586
623623
624624 client->urgent = state;
625625
626 client_setup_border(client, client->window == frame_focused_window(g_cur_frame));
626 client_setup_border(client, client == frame_focused_client(g_cur_frame));
627627
628628 XWMHints *wmh;
629629 if(!(wmh = XGetWMHints(g_display, client->window)))
648648 return;
649649 }
650650
651 Window focused_window = frame_focused_window(g_cur_frame);
652 if ((focused_window == client->window)
651 HSClient* focused_client = frame_focused_client(g_cur_frame);
652 if ((focused_client == client)
653653 && wmh->flags & XUrgencyHint) {
654654 // remove urgency hint if window is focused
655655 wmh->flags &= ~XUrgencyHint;
660660 client->urgent = newval;
661661 char winid_str[STRING_BUF_SIZE];
662662 snprintf(winid_str, STRING_BUF_SIZE, "0x%lx", client->window);
663 client_setup_border(client, focused_window == client->window);
663 client_setup_border(client, focused_client == client);
664664 hook_emit_list("urgent", client->urgent ? "on":"off", winid_str, NULL);
665665 tag_set_flags_dirty();
666666 }
699699 }
700700
701701 HSClient* get_current_client() {
702 Window win = frame_focused_window(g_cur_frame);
703 if (!win) return NULL;
704 return get_client_from_window(win);
702 return frame_focused_client(g_cur_frame);
705703 }
706704
707705 void client_set_fullscreen(HSClient* client, bool state) {
779777 }
780778
781779 unsigned long get_window_border_color(HSClient* client) {
782 Window win = client->window;
783 unsigned long current_border_color = (win == frame_focused_window(g_cur_frame)
780 unsigned long current_border_color = (client == frame_focused_client(g_cur_frame)
784781 ? g_window_border_active_color
785782 : g_window_border_normal_color);
786783 if (client->urgent)
812809 Window string_to_client(char* str, HSClient** ret_client) {
813810 Window win = 0;
814811 if (!strcmp(str, "")) {
815 win = frame_focused_window(g_cur_frame);
812 HSClient* client = get_current_client();
813 win = client ? client->window : 0;
816814 if (ret_client) {
817 *ret_client = get_client_from_window(win);
815 *ret_client = client;
818816 }
819817 } else if (!strcmp(str, "urgent")) {
820818 HSClient* client = get_urgent_client();
306306 // only steal focus it allowed to the current source
307307 // (i.e. me->data.l[0] in this case as specified by EWMH)
308308 if (focus_stealing_allowed(me->data.l[0])) {
309 focus_window(me->window, true, true);
309 HSClient* client = get_client_from_window(me->window);
310 if (client) {
311 focus_client(client, true, true);
312 }
310313 }
311314 break;
312315
149149 return frame;
150150 }
151151
152 void frame_insert_window(HSFrame* frame, Window window) {
152 void frame_insert_client(HSFrame* frame, struct HSClient* client) {
153153 if (frame->type == TYPE_CLIENTS) {
154154 // insert it here
155 Window* buf = frame->content.clients.buf;
155 HSClient** buf = frame->content.clients.buf;
156156 // append it to buf
157157 size_t count = frame->content.clients.count;
158158 count++;
159159 // insert it after the selection
160160 int index = frame->content.clients.selection + 1;
161161 index = CLAMP(index, 0, count - 1);
162 buf = g_renew(Window, buf, count);
162 buf = g_renew(HSClient*, buf, count);
163163 // shift other windows to the back to insert the new one at index
164164 memmove(buf + index + 1, buf + index, sizeof(*buf) * (count - index - 1));
165 buf[index] = window;
165 buf[index] = client;
166166 // write results back
167167 frame->content.clients.count = count;
168168 frame->content.clients.buf = buf;
170170 if (g_cur_frame == frame
171171 && frame->content.clients.selection >= (count-1)) {
172172 frame->content.clients.selection = count - 1;
173 window_focus(window);
173 window_focus(client->window);
174174 }
175175 } else { /* frame->type == TYPE_FRAMES */
176176 HSLayout* layout = &frame->content.layout;
177 frame_insert_window((layout->selection == 0)? layout->a : layout->b, window);
177 frame_insert_client((layout->selection == 0)? layout->a : layout->b, client);
178178 }
179179 }
180180
204204 return lookup_frame(new_root, new_index);
205205 }
206206
207 HSFrame* find_frame_with_window(HSFrame* frame, Window window) {
207 HSFrame* find_frame_with_client(HSFrame* frame, struct HSClient* client) {
208208 if (frame->type == TYPE_CLIENTS) {
209 Window* buf = frame->content.clients.buf;
209 HSClient** buf = frame->content.clients.buf;
210210 size_t count = frame->content.clients.count;
211211 for (int i = 0; i < count; i++) {
212 if (buf[i] == window) {
212 if (buf[i] == client) {
213213 return frame;
214214 }
215215 }
216216 return NULL;
217217 } else { /* frame->type == TYPE_FRAMES */
218 HSFrame* found = find_frame_with_window(frame->content.layout.a, window);
218 HSFrame* found = find_frame_with_client(frame->content.layout.a, client);
219219 if (!found) {
220 found = find_frame_with_window(frame->content.layout.b, window);
220 found = find_frame_with_client(frame->content.layout.b, client);
221221 }
222222 return found;
223223 }
224224 }
225225
226 bool frame_remove_window(HSFrame* frame, Window window) {
226 bool frame_remove_client(HSFrame* frame, HSClient* client) {
227227 if (frame->type == TYPE_CLIENTS) {
228 Window* buf = frame->content.clients.buf;
228 HSClient** buf = frame->content.clients.buf;
229229 size_t count = frame->content.clients.count;
230230 int i;
231231 for (i = 0; i < count; i++) {
232 if (buf[i] == window) {
232 if (buf[i] == client) {
233233 // if window was found
234234 // them remove it
235 memmove(buf+i, buf+i+1, sizeof(Window)*(count - i - 1));
235 memmove(buf+i, buf+i+1, sizeof(buf[0])*(count - i - 1));
236236 count--;
237 buf = g_renew(Window, buf, count);
237 buf = g_renew(HSClient*, buf, count);
238238 frame->content.clients.buf = buf;
239239 frame->content.clients.count = count;
240240 // find out new selection
251251 }
252252 return false;
253253 } else { /* frame->type == TYPE_FRAMES */
254 bool found = frame_remove_window(frame->content.layout.a, window);
255 found = found || frame_remove_window(frame->content.layout.b, window);
254 bool found = frame_remove_client(frame->content.layout.a, client);
255 found = found || frame_remove_client(frame->content.layout.b, client);
256256 return found;
257257 }
258258 }
259259
260 void frame_destroy(HSFrame* frame, Window** buf, size_t* count) {
260 void frame_destroy(HSFrame* frame, HSClient*** buf, size_t* count) {
261261 if (frame->type == TYPE_CLIENTS) {
262262 *buf = frame->content.clients.buf;
263263 *count = frame->content.clients.count;
264264 } else { /* frame->type == TYPE_FRAMES */
265265 size_t c1, c2;
266 Window *buf1, *buf2;
266 HSClient **buf1, **buf2;
267267 frame_destroy(frame->content.layout.a, &buf1, &c1);
268268 frame_destroy(frame->content.layout.b, &buf2, &c2);
269269 // append buf2 to buf1
270 buf1 = g_renew(Window, buf1, c1 + c2);
271 memcpy(buf1+c1, buf2, sizeof(Window) * c2);
270 buf1 = g_renew(HSClient*, buf1, c1 + c2);
271 memcpy(buf1+c1, buf2, sizeof(buf1[0]) * c2);
272272 // free unused things
273273 g_free(buf2);
274274 // return;
289289 LAYOUT_DUMP_WHITESPACES[0],
290290 g_layout_names[frame->content.clients.layout],
291291 frame->content.clients.selection);
292 Window* buf = frame->content.clients.buf;
292 HSClient** buf = frame->content.clients.buf;
293293 size_t i, count = frame->content.clients.count;
294294 for (i = 0; i < count; i++) {
295295 g_string_append_printf(output, "%c0x%lx",
296296 LAYOUT_DUMP_WHITESPACES[0],
297 buf[i]);
297 buf[i]->window);
298298 }
299299 g_string_append_c(output, LAYOUT_DUMP_BRACKETS[1]);
300300 } else {
423423 // ensure that it is a client frame
424424 if (frame->type == TYPE_FRAMES) {
425425 // remove childs
426 Window *buf1, *buf2;
426 HSClient **buf1, **buf2;
427427 size_t count1, count2;
428428 frame_destroy(frame->content.layout.a, &buf1, &count1);
429429 frame_destroy(frame->content.layout.b, &buf2, &count2);
430430
431431 // merge bufs
432432 size_t count = count1 + count2;
433 Window* buf = g_new(Window, count);
434 memcpy(buf, buf1, sizeof(Window) * count1);
435 memcpy(buf + count1, buf2, sizeof(Window) * count2);
433 HSClient** buf = g_new(HSClient*, count);
434 memcpy(buf, buf1, sizeof(buf[0]) * count1);
435 memcpy(buf + count1, buf2, sizeof(buf[0]) * count2);
436436 g_free(buf1);
437437 g_free(buf2);
438438
469469
470470 // remove window from old tag
471471 HSMonitor* clientmonitor = find_monitor_with_tag(client->tag);
472 if (!frame_remove_window(client->tag->frame, win)) {
472 if (!frame_remove_client(client->tag->frame, client)) {
473473 g_warning("window %lx was not found on tag %s\n",
474474 win, client->tag->name->str);
475475 }
479479 stack_remove_slice(client->tag->stack, client->slice);
480480
481481 // insert it to buf
482 Window* buf = frame->content.clients.buf;
482 HSClient** buf = frame->content.clients.buf;
483483 size_t count = frame->content.clients.count;
484484 count++;
485485 index = CLAMP(index, 0, count - 1);
486 buf = g_renew(Window, buf, count);
486 buf = g_renew(HSClient*, buf, count);
487487 memmove(buf + index + 1, buf + index,
488 sizeof(Window) * (count - index - 1));
489 buf[index] = win;
488 sizeof(buf[0]) * (count - index - 1));
489 buf[index] = client;
490490 frame->content.clients.buf = buf;
491491 frame->content.clients.count = count;
492492
548548 // list of clients
549549 g_string_append_printf(output, "%s:",
550550 g_layout_names[frame->content.clients.layout]);
551 Window* buf = frame->content.clients.buf;
551 HSClient** buf = frame->content.clients.buf;
552552 size_t i, count = frame->content.clients.count;
553553 for (i = 0; i < count; i++) {
554 g_string_append_printf(output, " 0x%lx", buf[i]);
554 g_string_append_printf(output, " 0x%lx", buf[i]->window);
555555 }
556556 if (g_cur_frame == frame) {
557557 g_string_append(output, " [FOCUS]");
604604 } else {
605605 /* if(frame->type == TYPE_CLIENTS) */
606606 frame_set_visible(frame, false);
607 Window* buf = frame->content.clients.buf;
607 HSClient** buf = frame->content.clients.buf;
608608 size_t count = frame->content.clients.count;
609609 size_t selection = frame->content.clients.selection;
610610 /* border color */
611611 for (int i = 0; i < count; i++) {
612 HSClient* client = get_client_from_window(buf[i]);
612 HSClient* client = buf[i];
613613 client_setup_border(client, (g_cur_frame == frame) && (i == selection));
614614 client_resize_floating(client, m);
615615 }
672672 }
673673
674674 void frame_apply_client_layout_linear(HSFrame* frame, XRectangle rect, bool vertical) {
675 Window* buf = frame->content.clients.buf;
675 HSClient** buf = frame->content.clients.buf;
676676 size_t count = frame->content.clients.count;
677677 int selection = frame->content.clients.selection;
678678 XRectangle cur = rect;
696696 step_x = cur.width;
697697 }
698698 for (int i = 0; i < count; i++) {
699 HSClient* client = get_client_from_window(buf[i]);
699 HSClient* client = buf[i];
700700 // add the space, if count does not divide frameheight without remainder
701701 cur.height += (i == count-1) ? last_step_y : 0;
702702 cur.width += (i == count-1) ? last_step_x : 0;
716716 }
717717
718718 void frame_apply_client_layout_max(HSFrame* frame, XRectangle rect) {
719 Window* buf = frame->content.clients.buf;
719 HSClient** buf = frame->content.clients.buf;
720720 size_t count = frame->content.clients.count;
721721 int selection = frame->content.clients.selection;
722722 for (int i = 0; i < count; i++) {
723 HSClient* client = get_client_from_window(buf[i]);
723 HSClient* client = buf[i];
724724 client_setup_border(client, (g_cur_frame == frame) && (i == selection));
725725 client_resize_tiling(client, rect, frame);
726726 if (i == selection) {
743743 }
744744
745745 void frame_apply_client_layout_grid(HSFrame* frame, XRectangle rect) {
746 Window* buf = frame->content.clients.buf;
746 HSClient** buf = frame->content.clients.buf;
747747 size_t count = frame->content.clients.count;
748748 int selection = frame->content.clients.selection;
749749 if (count == 0) {
776776 }
777777
778778 // apply size
779 HSClient* client = get_client_from_window(buf[i]);
779 HSClient* client = buf[i];
780780 client_setup_border(client, (g_cur_frame == frame) && (i == selection));
781781 client_resize_tiling(client, cur, frame);
782782 cur.x += width;
929929 return HERBST_INVALID_ARGUMENT;
930930 }
931931 tag_move_client(client, get_current_monitor()->tag);
932 focus_window(client->window, false, false);
932 focus_client(client, false, false);
933933 return 0;
934934 }
935935
950950 index = frame->content.clients.count - 1;
951951 }
952952 frame->content.clients.selection = index;
953 Window window = frame->content.clients.buf[index];
953 Window window = frame->content.clients.buf[index]->window;
954954 window_focus(window);
955955 return 0;
956956 }
975975 index += count;
976976 index %= count;
977977 frame->content.clients.selection = index;
978 Window window = frame->content.clients.buf[index];
978 Window window = frame->content.clients.buf[index]->window;
979979 window_focus(window);
980980 return 0;
981981 }
11351135 index %= frame->content.clients.count;
11361136 frame->content.clients.selection = index;
11371137 }
1138 Window w = frame_focused_window(g_cur_frame);
1139 if (w) {
1140 HSClient* c = get_client_from_window(w);
1141 if (c) {
1142 client_raise(c);
1143 }
1138 HSClient* c = frame_focused_client(g_cur_frame);
1139 if (c) {
1140 client_raise(c);
11441141 }
11451142 monitor_apply_layout(get_current_monitor());
11461143 return 0;
14311428 if (!external_only &&
14321429 (index = frame_inner_neighbour_index(g_cur_frame, direction)) != -1) {
14331430 int selection = g_cur_frame->content.clients.selection;
1434 Window* buf = g_cur_frame->content.clients.buf;
1431 HSClient** buf = g_cur_frame->content.clients.buf;
14351432 // if internal neighbour was found, then swap
1436 Window tmp = buf[selection];
1433 HSClient* tmp = buf[selection];
14371434 buf[selection] = buf[index];
14381435 buf[index] = tmp;
14391436
14421439 monitor_apply_layout(get_current_monitor());
14431440 } else {
14441441 HSFrame* neighbour = frame_neighbour(g_cur_frame, direction);
1445 Window win = frame_focused_window(g_cur_frame);
1446 if (win && neighbour != NULL) { // if neighbour was found
1442 HSClient* client = frame_focused_client(g_cur_frame);
1443 if (client && neighbour != NULL) { // if neighbour was found
14471444 // move window to neighbour
1448 frame_remove_window(g_cur_frame, win);
1449 frame_insert_window(neighbour, win);
1445 frame_remove_client(g_cur_frame, client);
1446 frame_insert_client(neighbour, client);
14501447
14511448 // change selection in parent
14521449 HSFrame* parent = neighbour->parent;
14571454 HSFrame* frame = g_cur_frame;
14581455 assert(frame);
14591456 int i;
1460 Window* buf = frame->content.clients.buf;
1457 HSClient** buf = frame->content.clients.buf;
14611458 size_t count = frame->content.clients.count;
14621459 for (i = 0; i < count; i++) {
1463 if (buf[i] == win) {
1460 if (buf[i] == client) {
14641461 frame->content.clients.selection = i;
1465 window_focus(buf[i]);
1462 window_focus(buf[i]->window);
14661463 break;
14671464 }
14681465 }
14821479 //XSetInputFocus(g_display, g_root, RevertToPointerRoot, CurrentTime);
14831480 }
14841481
1485 Window frame_focused_window(HSFrame* frame) {
1482 HSClient* frame_focused_client(HSFrame* frame) {
14861483 if (!frame) {
1487 return (Window)0;
1484 return NULL;
14881485 }
14891486 // follow the selection to a leave
14901487 while (frame->type == TYPE_FRAMES) {
14961493 int selection = frame->content.clients.selection;
14971494 return frame->content.clients.buf[selection];
14981495 } // else, if there are no windows
1499 return (Window)0;
1496 return NULL;
15001497 }
15011498
15021499 // try to focus window in frame
15031500 // it does not require anything from the frame. it may be infocused or even
15041501 // hidden.
15051502 // returns true if win was found and focused, else returns false
1506 bool frame_focus_window(HSFrame* frame, Window win) {
1503 bool frame_focus_client(HSFrame* frame, HSClient* client) {
15071504 if (!frame) {
15081505 return false;
15091506 }
15101507 if (frame->type == TYPE_CLIENTS) {
15111508 int i;
15121509 size_t count = frame->content.clients.count;
1513 Window* buf = frame->content.clients.buf;
1510 HSClient** buf = frame->content.clients.buf;
15141511 // search for win in buf
15151512 for (i = 0; i < count; i++) {
1516 if (buf[i] == win) {
1513 if (buf[i] == client) {
15171514 // if found, set focus to it
15181515 frame->content.clients.selection = i;
15191516 return true;
15231520 } else {
15241521 // type == TYPE_FRAMES
15251522 // search in subframes
1526 bool found = frame_focus_window(frame->content.layout.a, win);
1523 bool found = frame_focus_client(frame->content.layout.a, client);
15271524 if (found) {
15281525 // set selection to first frame
15291526 frame->content.layout.selection = 0;
15301527 return true;
15311528 }
1532 found = frame_focus_window(frame->content.layout.b, win);
1529 found = frame_focus_client(frame->content.layout.b, client);
15331530 if (found) {
15341531 // set selection to second frame
15351532 frame->content.layout.selection = 1;
15431540 // switch_tag tells, whether to switch tag to focus to window
15441541 // switch_monitor tells, whether to switch monitor to focus to window
15451542 // returns if window was focused or not
1546 bool focus_window(Window win, bool switch_tag, bool switch_monitor) {
1547 HSClient* client = get_client_from_window(win);
1543 bool focus_client(struct HSClient* client, bool switch_tag, bool switch_monitor) {
15481544 if (!client) {
15491545 // client is not managed
15501546 return false;
15821578 }
15831579 // now the right tag is visible
15841580 // now focus it
1585 bool found = frame_focus_window(tag->frame, win);
1581 bool found = frame_focus_client(tag->frame, client);
15861582 frame_focus_recursive(tag->frame);
15871583 monitor_apply_layout(cur_mon);
15881584 monitors_unlock();
16001596 frame_unfocus();
16011597 if (frame->content.clients.count) {
16021598 int selection = frame->content.clients.selection;
1603 window_focus(frame->content.clients.buf[selection]);
1599 window_focus(frame->content.clients.buf[selection]->window);
16041600 } else {
16051601 window_unfocus_last();
16061602 }
16491645 frame_set_visible(frame, false);
16501646 if (frame->type == TYPE_CLIENTS) {
16511647 int i;
1652 Window* buf = frame->content.clients.buf;
1648 HSClient** buf = frame->content.clients.buf;
16531649 size_t count = frame->content.clients.count;
16541650 for (i = 0; i < count; i++) {
1655 window_hide(buf[i]);
1651 window_hide(buf[i]->window);
16561652 }
16571653 }
16581654 }
16651661 static void frame_show_clients(HSFrame* frame) {
16661662 if (frame->type == TYPE_CLIENTS) {
16671663 int i;
1668 Window* buf = frame->content.clients.buf;
1664 HSClient** buf = frame->content.clients.buf;
16691665 size_t count = frame->content.clients.count;
16701666 for (i = 0; i < count; i++) {
1671 window_show(buf[i]);
1667 window_show(buf[i]->window);
16721668 }
16731669 }
16741670 }
17191715 second = parent->content.layout.a;
17201716 }
17211717 size_t count;
1722 Window* wins;
1718 HSClient** wins;
17231719 // get all wins from first child
17241720 frame_destroy(first, &wins, &count);
17251721 // and insert them to other child.. inefficiently
17261722 int i;
17271723 for (i = 0; i < count; i++) {
1728 frame_insert_window(second, wins[i]);
1724 frame_insert_client(second, wins[i]);
17291725 }
17301726 g_free(wins);
17311727 XDestroyWindow(g_display, parent->window);
17511747 }
17521748
17531749 int close_or_remove_command(int argc, char** argv) {
1754 if (frame_focused_window(g_cur_frame)) {
1750 if (frame_focused_client(g_cur_frame)) {
17551751 return window_close_current();
17561752 } else {
17571753 return frame_remove_command(argc, argv);
17881784 }
17891785 } else {
17901786 // frame->type == TYPE_CLIENTS
1791 Window* buf = frame->content.clients.buf;
1787 HSClient** buf = frame->content.clients.buf;
17921788 size_t count = frame->content.clients.count;
17931789 HSClient* client;
17941790 for (int i = 0; i < count; i++) {
1795 client = get_client_from_window(buf[i]);
1791 client = buf[i];
17961792 // do action for each client
17971793 status = action(client, data);
17981794 if (0 != status) {
7171 union {
7272 HSLayout layout;
7373 struct {
74 Window* buf;
74 struct HSClient** buf;
7575 size_t count;
7676 int selection;
7777 int layout;
9696 void layout_destroy();
9797 // for frames
9898 HSFrame* frame_create_empty(HSFrame* parent, HSTag* parenttag);
99 void frame_insert_window(HSFrame* frame, Window window);
99 void frame_insert_client(HSFrame* frame, struct HSClient* client);
100100 HSFrame* lookup_frame(HSFrame* root, char* path);
101101 HSFrame* frame_current_selection();
102102 HSFrame* frame_current_selection_below(HSFrame* frame);
103103 // finds the subframe of frame that contains the window
104 HSFrame* find_frame_with_window(HSFrame* frame, Window window);
104 HSFrame* find_frame_with_client(HSFrame* frame, struct HSClient* client);
105105 // removes window from a frame/subframes
106106 // returns true, if window was found. else: false
107 bool frame_remove_window(HSFrame* frame, Window window);
107 bool frame_remove_client(HSFrame* frame, struct HSClient* client);
108108 // destroys a frame and all its childs
109109 // then all Windows in it are collected and returned
110110 // YOU have to g_free the resulting window-buf
111 void frame_destroy(HSFrame* frame, Window** buf, size_t* count);
111 void frame_destroy(HSFrame* frame, struct HSClient*** buf, size_t* count);
112112 void frame_split(HSFrame* frame, int align, int fraction);
113113 int frame_split_command(int argc, char** argv, GString* output);
114114 int frame_change_fraction_command(int argc, char** argv, GString* output);
162162
163163 // returns the Window that is focused
164164 // returns 0 if there is none
165 Window frame_focused_window(HSFrame* frame);
166 bool frame_focus_window(HSFrame* frame, Window win);
167 bool focus_window(Window win, bool switch_tag, bool switch_monitor);
165 struct HSClient* frame_focused_client(HSFrame* frame);
166 bool frame_focus_client(HSFrame* frame, struct HSClient* client);
167 bool focus_client(struct HSClient* client, bool switch_tag, bool switch_monitor);
168168 // moves a window to an other frame
169169 int frame_move_window_command(int argc, char** argv, GString* output);
170170 /// removes the current frame
421421 HSClient* client = NULL;
422422 string_to_client(argv[1], &client);
423423 if (client) {
424 focus_window(client->window, true, true);
424 focus_client(client, true, true);
425425 return 0;
426426 } else {
427427 g_string_append_printf(output,
754754 if (mouse_binding_find(be->state, be->button)) {
755755 mouse_start_drag(event);
756756 } else {
757 focus_window(be->window, false, true);
758 if (*g_raise_on_click) {
759 HSClient* client = get_client_from_window(be->window);
760 if (client) {
761 client_raise(client);
757 HSClient* client = get_client_from_window(be->window);
758 if (client) {
759 focus_client(client, false, true);
760 if (*g_raise_on_click) {
761 client_raise(client);
762762 }
763763 }
764764 }
805805 HSClient* c = get_client_from_window(ce->window);
806806 HSFrame* target;
807807 if (c && c->tag->floating == false
808 && (target = find_frame_with_window(c->tag->frame, ce->window))
808 && (target = find_frame_with_client(c->tag->frame, c))
809809 && target->content.clients.layout == LAYOUT_MAX
810 && frame_focused_window(target) != ce->window) {
810 && frame_focused_client(target) != c) {
811811 // don't allow focus_follows_mouse if another window would be
812812 // hidden during that focus change (which only occurs in max layout)
813 } else {
814 focus_window(ce->window, false, true);
813 } else if (c) {
814 focus_client(c, false, true);
815815 }
816816 }
817817 }
12071207 buf[0] = monitor->stacking_window;
12081208 stack_to_window_buf(monitor->tag->stack, buf + 1, count - 1, false, NULL);
12091209 /* remove a focused fullscreen client */
1210 Window win = frame_focused_window(monitor->tag->frame);
1211 HSClient* client = win ? get_client_from_window(win) : NULL;
1210 HSClient* client = frame_focused_client(monitor->tag->frame);
12121211 if (client && client->fullscreen) {
12131212 XRaiseWindow(g_display, client->window);
12141213 int idx = array_find(buf, count, sizeof(*buf), &client->window);
4141
4242 static void tag_free(HSTag* tag) {
4343 if (tag->frame) {
44 Window* buf;
44 HSClient** buf;
4545 size_t count;
4646 frame_destroy(tag->frame, &buf, &count);
4747 if (count) {
306306 // prevent dangling tag_previous pointers
307307 all_monitors_replace_previous_tag(tag, target);
308308 // save all these windows
309 Window* buf;
309 HSClient** buf;
310310 size_t count;
311311 frame_destroy(tag->frame, &buf, &count);
312312 tag->frame = NULL;
313313 int i;
314314 for (i = 0; i < count; i++) {
315 HSClient* client = get_client_from_window(buf[i]);
315 HSClient* client = buf[i];
316316 stack_remove_slice(client->tag->stack, client->slice);
317317 client->tag = target;
318318 stack_insert_slice(client->tag->stack, client->slice);
319319 ewmh_window_update_tag(client->window, client->tag);
320 frame_insert_window(target->frame, buf[i]);
320 frame_insert_client(target->frame, buf[i]);
321321 }
322322 HSMonitor* monitor_target = find_monitor_with_tag(target);
323323 if (monitor_target) {
324324 // if target monitor is viewed, then show windows
325325 monitor_apply_layout(monitor_target);
326326 for (i = 0; i < count; i++) {
327 window_show(buf[i]);
327 window_show(buf[i]->window);
328328 }
329329 }
330330 g_free(buf);
464464 }
465465
466466 void tag_move_focused_client(HSTag* target) {
467 Window window = frame_focused_window(get_current_monitor()->tag->frame);
468 if (window == 0) {
467 HSClient* client = frame_focused_client(get_current_monitor()->tag->frame);
468 if (client == 0) {
469469 // nothing to do
470470 return;
471471 }
472 HSClient* client = get_client_from_window(window);
473 assert(client);
474472 tag_move_client(client, target);
475473 }
476474
482480 return;
483481 }
484482 HSMonitor* monitor_target = find_monitor_with_tag(target);
485 frame_remove_window(tag_source->frame, client->window);
483 frame_remove_client(tag_source->frame, client);
486484 // insert window into target
487 frame_insert_window(target->frame, client->window);
485 frame_insert_client(target->frame, client);
488486 // enfoce it to be focused on the target tag
489 frame_focus_window(target->frame, client->window);
487 frame_focus_client(target->frame, client);
490488 stack_remove_slice(client->tag->stack, client->slice);
491489 client->tag = target;
492490 stack_insert_slice(client->tag->stack, client->slice);
513511 }
514512
515513 void tag_update_focus_layer(HSTag* tag) {
516 HSClient* focus = get_client_from_window(frame_focused_window(tag->frame));
514 HSClient* focus = frame_focused_client(tag->frame);
517515 stack_clear_layer(tag->stack, LAYER_FOCUS);
518516 if (focus) {
519517 // enforce raise_on_focus_temporarily if there is at least one