2011-02-21 01:43:39 +01:00
|
|
|
/*
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
2011-10-23 00:40:02 +02:00
|
|
|
*
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
2015-04-04 02:17:56 +02:00
|
|
|
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
|
2011-10-23 00:40:02 +02:00
|
|
|
*
|
|
|
|
* output.c: Output (monitor) related functions.
|
|
|
|
*
|
2011-02-21 01:43:39 +01:00
|
|
|
*/
|
|
|
|
#include "all.h"
|
|
|
|
|
|
|
|
/*
|
2018-08-17 05:45:20 +02:00
|
|
|
* Returns the content container below the given output container.
|
2011-02-21 01:43:39 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
Con *output_get_content(Con *output) {
|
|
|
|
Con *child;
|
|
|
|
|
2014-06-19 11:20:32 +02:00
|
|
|
TAILQ_FOREACH(child, &(output->nodes_head), nodes)
|
|
|
|
if (child->type == CT_CON)
|
|
|
|
return child;
|
2011-02-21 01:43:39 +01:00
|
|
|
|
2013-01-25 14:53:15 +01:00
|
|
|
return NULL;
|
2011-02-21 01:43:39 +01:00
|
|
|
}
|
2015-03-04 09:22:25 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns an 'output' corresponding to one of left/right/down/up or a specific
|
|
|
|
* output name.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
Output *get_output_from_string(Output *current_output, const char *output_str) {
|
2016-09-30 17:28:02 +02:00
|
|
|
if (strcasecmp(output_str, "current") == 0) {
|
|
|
|
return get_output_for_con(focused);
|
|
|
|
} else if (strcasecmp(output_str, "left") == 0) {
|
|
|
|
return get_output_next_wrap(D_LEFT, current_output);
|
|
|
|
} else if (strcasecmp(output_str, "right") == 0) {
|
|
|
|
return get_output_next_wrap(D_RIGHT, current_output);
|
|
|
|
} else if (strcasecmp(output_str, "up") == 0) {
|
|
|
|
return get_output_next_wrap(D_UP, current_output);
|
|
|
|
} else if (strcasecmp(output_str, "down") == 0) {
|
|
|
|
return get_output_next_wrap(D_DOWN, current_output);
|
|
|
|
}
|
|
|
|
|
2017-08-20 00:19:45 +02:00
|
|
|
return get_output_by_name(output_str, true);
|
2016-09-30 17:28:02 +02:00
|
|
|
}
|
|
|
|
|
2017-09-09 09:18:29 +02:00
|
|
|
/*
|
|
|
|
* Retrieves the primary name of an output.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
char *output_primary_name(Output *output) {
|
2017-09-09 09:37:37 +02:00
|
|
|
return SLIST_FIRST(&output->names_head)->name;
|
2017-09-09 09:18:29 +02:00
|
|
|
}
|
|
|
|
|
2016-09-30 17:28:02 +02:00
|
|
|
Output *get_output_for_con(Con *con) {
|
|
|
|
Con *output_con = con_get_output(con);
|
2017-08-20 00:19:45 +02:00
|
|
|
Output *output = get_output_by_name(output_con->name, true);
|
2019-03-21 22:51:57 +01:00
|
|
|
assert(output != NULL);
|
2015-03-04 09:22:25 +01:00
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
2015-08-26 21:06:53 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterates over all outputs and pushes sticky windows to the currently visible
|
|
|
|
* workspace on that output.
|
|
|
|
*
|
2018-10-11 11:05:31 +02:00
|
|
|
* old_focus is used to determine if a sticky window is going to be focused.
|
|
|
|
* old_focus might be different than the currently focused container because the
|
|
|
|
* caller might need to temporarily change the focus and then call
|
|
|
|
* output_push_sticky_windows. For example, workspace_show needs to set focus to
|
|
|
|
* one of its descendants first, then call output_push_sticky_windows that
|
|
|
|
* should focus a sticky window if it was the focused in the previous workspace.
|
|
|
|
*
|
2015-08-26 21:06:53 +02:00
|
|
|
*/
|
2018-10-11 11:05:31 +02:00
|
|
|
void output_push_sticky_windows(Con *old_focus) {
|
2015-08-26 21:06:53 +02:00
|
|
|
Con *output;
|
2015-09-17 22:52:56 +02:00
|
|
|
TAILQ_FOREACH(output, &(croot->focus_head), focused) {
|
2015-08-26 21:06:53 +02:00
|
|
|
Con *workspace, *visible_ws = NULL;
|
|
|
|
GREP_FIRST(visible_ws, output_get_content(output), workspace_is_visible(child));
|
|
|
|
|
|
|
|
/* We use this loop instead of TAILQ_FOREACH to avoid problems if the
|
|
|
|
* sticky window was the last window on that workspace as moving it in
|
|
|
|
* this case will close the workspace. */
|
2015-09-17 22:52:56 +02:00
|
|
|
for (workspace = TAILQ_FIRST(&(output_get_content(output)->focus_head));
|
|
|
|
workspace != TAILQ_END(&(output_get_content(output)->focus_head));) {
|
2015-08-26 21:06:53 +02:00
|
|
|
Con *current_ws = workspace;
|
2015-09-17 22:52:56 +02:00
|
|
|
workspace = TAILQ_NEXT(workspace, focused);
|
2015-08-26 21:06:53 +02:00
|
|
|
|
|
|
|
/* Since moving the windows actually removes them from the list of
|
|
|
|
* floating windows on this workspace, here too we need to use
|
|
|
|
* another loop than TAILQ_FOREACH. */
|
|
|
|
Con *child;
|
2015-09-17 22:52:56 +02:00
|
|
|
for (child = TAILQ_FIRST(&(current_ws->focus_head));
|
|
|
|
child != TAILQ_END(&(current_ws->focus_head));) {
|
2015-08-26 21:06:53 +02:00
|
|
|
Con *current = child;
|
2015-09-17 22:52:56 +02:00
|
|
|
child = TAILQ_NEXT(child, focused);
|
2018-10-11 11:05:31 +02:00
|
|
|
if (current->type != CT_FLOATING_CON || !con_is_sticky(current)) {
|
2015-09-17 22:52:56 +02:00
|
|
|
continue;
|
2018-10-11 11:05:31 +02:00
|
|
|
}
|
2015-08-26 21:06:53 +02:00
|
|
|
|
2018-10-11 11:05:31 +02:00
|
|
|
bool ignore_focus = (old_focus == NULL) || (current != old_focus->parent);
|
|
|
|
con_move_to_workspace(current, visible_ws, true, false, ignore_focus);
|
|
|
|
if (!ignore_focus) {
|
|
|
|
Con *current_ws = con_get_workspace(focused);
|
|
|
|
con_activate(con_descend_focused(current));
|
|
|
|
/* Pushing sticky windows shouldn't change the focused workspace. */
|
|
|
|
con_activate(con_descend_focused(current_ws));
|
2015-09-17 22:52:56 +02:00
|
|
|
}
|
2015-08-26 21:06:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|