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"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the output container below the given output container.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
if (output_con == NULL) {
|
|
|
|
ELOG("Could not get the output container for con = %p.\n", con);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-20 00:19:45 +02:00
|
|
|
Output *output = get_output_by_name(output_con->name, true);
|
2016-09-30 17:28:02 +02:00
|
|
|
if (output == NULL) {
|
|
|
|
ELOG("Could not get output from name \"%s\".\n", output_con->name);
|
|
|
|
return 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.
|
|
|
|
*
|
|
|
|
*/
|
2015-09-17 22:52:56 +02:00
|
|
|
void output_push_sticky_windows(Con *to_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);
|
|
|
|
if (current->type != CT_FLOATING_CON)
|
|
|
|
continue;
|
2015-08-26 21:06:53 +02:00
|
|
|
|
2015-09-17 22:52:56 +02:00
|
|
|
if (con_is_sticky(current)) {
|
2017-12-09 21:17:48 +01:00
|
|
|
bool ignore_focus = (to_focus == NULL) || (current != to_focus->parent);
|
|
|
|
con_move_to_workspace(current, visible_ws, true, false, ignore_focus);
|
2015-09-17 22:52:56 +02:00
|
|
|
}
|
2015-08-26 21:06:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|