2 #define I3__FILE__ "workspace.c"
37 DLOG(
"Auto orientation. Workspace size set to (%d,%d), setting layout to %d.\n",
51 Con *output, *workspace = NULL;
56 if (workspace == NULL) {
57 LOG(
"Creating new workspace \"%s\"\n", num);
69 if (strcmp(assignment->
name, num) == 0) {
70 DLOG(
"Found workspace name assignment to output \"%s\"\n", assignment->
output);
74 DLOG(
"Found workspace number assignment to output \"%s\"\n", assignment->
output);
80 LOG(
"got output %p with content %p\n", output, content);
83 workspace =
con_new(NULL, NULL);
85 sasprintf(&name,
"[i3 con] workspace %s", num);
88 workspace->
type = CT_WORKSPACE;
92 workspace->
num = parsed_num;
93 LOG(
"num = %d\n", workspace->
num);
95 workspace->
parent = content;
107 }
else if (created != NULL) {
132 if (strlen(bind->
command) < strlen(
"workspace ") ||
133 strncasecmp(bind->
command,
"workspace", strlen(
"workspace")) != 0)
136 const char *target = bind->
command + strlen(
"workspace ");
137 while (*target ==
' ' || *target ==
'\t')
144 if (strncasecmp(target,
"next", strlen(
"next")) == 0 ||
145 strncasecmp(target,
"prev", strlen(
"prev")) == 0 ||
146 strncasecmp(target,
"next_on_output", strlen(
"next_on_output")) == 0 ||
147 strncasecmp(target,
"prev_on_output", strlen(
"prev_on_output")) == 0 ||
148 strncasecmp(target,
"number", strlen(
"number")) == 0 ||
149 strncasecmp(target,
"back_and_forth", strlen(
"back_and_forth")) == 0 ||
150 strncasecmp(target,
"current", strlen(
"current")) == 0)
153 if (target_name == NULL)
155 if (strncasecmp(target_name,
"__", strlen(
"__")) == 0) {
156 LOG(
"Cannot create workspace \"%s\". Names starting with __ are i3-internal.\n", target);
160 DLOG(
"Saving workspace name \"%s\"\n", target_name);
181 ws->
type = CT_WORKSPACE;
189 bool assigned =
false;
192 if (strcmp(assignment->
name, target_name) != 0 ||
193 strcmp(assignment->
output, output->
name) == 0)
206 exists = (current != NULL);
212 LOG(
"Used number %d for workspace with name %s\n", ws->
num, ws->
name);
220 DLOG(
"Getting next unused workspace by number\n");
230 exists = (current != NULL);
232 DLOG(
"result for ws %d: exists = %d\n", c, exists);
261 LOG(
"workspace visible? fs = %p, ws = %p\n", fs, ws);
273 if (current != exclude &&
275 current->
window != NULL &&
284 TAILQ_FOREACH(current, &(con->floating_head), floating_windows) {
285 if (current != exclude &&
287 current->
window != NULL &&
317 LOG(
"Ah, this one is sticky: %s / %p\n", current->
name, current);
323 LOG(
"No window found for this sticky group\n");
336 LOG(
"re-assigned window from src %p to dest %p\n", src, current);
339 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
356 DLOG(
"Resetting urgency flag of con %p by timer\n", con);
366 Con *current, *old = NULL;
385 if (workspace == current) {
386 DLOG(
"Not switching, already there.\n");
406 DLOG(
"switching to %p / %s\n", workspace, workspace->
name);
426 DLOG(
"Deferring reset of urgency flag of con %p on newly shown workspace %p\n",
435 DLOG(
"Resetting urgency timer of con %p on workspace %p\n",
444 DLOG(
"old = %p / %s\n", old, (old ? old->
name :
"(null)"));
453 LOG(
"Closing old workspace (%p / %s), it is empty\n", old, old->
name);
457 const unsigned char *payload;
459 y(get_buf, &payload, &length);
460 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE, (
const char *)payload);
476 if (old_output != new_output) {
511 Con *next = NULL, *first = NULL, *first_opposite = NULL;
514 if (current->
num == -1) {
516 if ((next =
TAILQ_NEXT(current, nodes)) != NULL)
518 bool found_current =
false;
524 if (child->type != CT_WORKSPACE)
528 if (!first_opposite && child->num != -1)
529 first_opposite = child;
530 if (child == current) {
531 found_current =
true;
532 }
else if (child->num == -1 && found_current) {
545 if (child->type != CT_WORKSPACE)
549 if (!first_opposite && child->num == -1)
550 first_opposite = child;
551 if (child->num == -1)
556 if (current->
num < child->num && (!next || child->
num < next->
num))
563 next = first_opposite ? first_opposite : first;
574 Con *prev = NULL, *first_opposite = NULL, *last = NULL;
577 if (current->
num == -1) {
579 prev =
TAILQ_PREV(current, nodes_head, nodes);
580 if (prev && prev->
num != -1)
583 bool found_current =
false;
589 if (child->type != CT_WORKSPACE)
593 if (!first_opposite && child->num != -1)
594 first_opposite = child;
595 if (child == current) {
596 found_current =
true;
597 }
else if (child->num == -1 && found_current) {
599 goto workspace_prev_end;
611 if (child->type != CT_WORKSPACE)
615 if (!first_opposite && child->num == -1)
616 first_opposite = child;
617 if (child->num == -1)
622 if (current->
num > child->num && (!prev || child->
num > prev->
num))
629 prev = first_opposite ? first_opposite : last;
644 if (current->
num == -1) {
650 if (child->type != CT_WORKSPACE)
652 if (child->num == -1)
657 if (current->
num < child->num && (!next || child->
num < next->
num))
664 bool found_current =
false;
666 if (child->type != CT_WORKSPACE)
668 if (child == current) {
669 found_current =
true;
670 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
672 goto workspace_next_on_output_end;
680 if (child->type != CT_WORKSPACE)
682 if (!next || (child->num != -1 && child->num < next->
num))
686 workspace_next_on_output_end:
698 DLOG(
"output = %s\n", output->
name);
700 if (current->
num == -1) {
702 prev =
TAILQ_PREV(current, nodes_head, nodes);
703 if (prev && prev->
num != -1)
708 if (child->type != CT_WORKSPACE || child->num == -1)
713 if (current->
num > child->num && (!prev || child->
num > prev->
num))
720 bool found_current =
false;
722 if (child->type != CT_WORKSPACE)
724 if (child == current) {
725 found_current =
true;
726 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
728 goto workspace_prev_on_output_end;
736 if (child->type != CT_WORKSPACE)
738 if (!prev || child->
num > prev->
num)
743 workspace_prev_on_output_end:
753 DLOG(
"No previous workspace name set. Not switching.\n");
766 DLOG(
"No previous workspace name set.\n");
782 TAILQ_FOREACH(child, &(con->floating_head), floating_windows)
795 bool old_flag = ws->
urgent;
797 DLOG(
"Workspace urgency flag changed from %d to %d\n", old_flag, ws->
urgent);
799 if (old_flag != ws->
urgent)
819 DLOG(
"Moving cons\n");
831 DLOG(
"Attaching new split (%p) to ws (%p)\n", split, ws);
852 DLOG(
"Attaching a window to workspace %p / %s\n", ws, ws->
name);
855 DLOG(
"Default layout, just attaching it to the workspace itself.\n");
859 DLOG(
"Non-default layout, creating a new split container\n");
868 DLOG(
"Attaching new split %p to workspace %p\n",
new, ws);
885 ELOG(
"Workspace %p / %s has no children to encapsulate\n", ws, ws->
name);
893 DLOG(
"Moving children of workspace %p / %s into container %p\n",
913 LOG(
"Trying to move workspace %p / %s to output \"%s\".\n", ws, ws->
name, name);
916 if (!current_output_con) {
917 ELOG(
"Could not get the output container for workspace %p / %s.\n", ws, ws->
name);
922 if (!current_output) {
923 ELOG(
"Cannot get current output. This is a bug in i3.\n");
928 ELOG(
"Could not get output from string \"%s\"\n", name);
933 LOG(
"got output %p with content %p\n", output, content);
936 LOG(
"Previously visible workspace = %p / %s\n", previously_visible_ws, previously_visible_ws->
name);
940 LOG(
"Creating a new workspace to replace \"%s\" (last on its output).\n", ws->
name);
943 bool used_assignment =
false;
946 if (assignment->
output == NULL || strcmp(assignment->
output, current_output->
name) != 0)
950 Con *workspace = NULL, *out;
953 !strcasecmp(child->name, assignment->
name));
954 if (workspace != NULL)
958 LOG(
"Creating workspace from assignment %s.\n", assignment->
name);
960 used_assignment =
true;
966 if (!used_assignment)
977 if (workspace_was_visible) {
981 LOG(
"workspace was visible, focusing %p / %s now\n", focus_ws, focus_ws->
name);
988 TAILQ_FOREACH(floating_con, &(ws->floating_head), floating_windows)
992 if (workspace_was_visible) {
1003 if (ws != previously_visible_ws)
1009 CALL(previously_visible_ws, on_remove_child);
Con * workspace_next(void)
Returns the next workspace.
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
void con_focus(Con *con)
Sets input focus to the given container.
void con_set_urgency(Con *con, bool urgent)
Set urgency flag to the container, all the parent containers and the workspace.
Con * workspace_prev_on_output(void)
Returns the previous workspace on the same output.
Output * get_output_from_string(Output *current_output, const char *output_str)
Returns an 'output' corresponding to one of left/right/down/up or a specific output name...
#define TAILQ_EMPTY(head)
Con * output_get_content(Con *output)
Returns the output container below the given output container.
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
struct bindings_head * bindings
static char * previous_workspace_name
Con * create_workspace_on_output(Output *output, Con *content)
Returns a pointer to a new workspace in the given output.
#define NODES_FOREACH_REVERSE(head)
static void workspace_reassign_sticky(Con *con)
void output_push_sticky_windows(Con *to_focus)
Iterates over all outputs and pushes sticky windows to the currently visible workspace on that output...
void workspace_update_urgent_flag(Con *ws)
Goes through all clients on the given workspace and updates the workspace’s urgent flag accordingly...
Stores which workspace (by name or number) goes to which output.
#define TAILQ_FOREACH(var, head, field)
Con * workspace_get(const char *num, bool *created)
Returns a pointer to the workspace with the given number (starting at 0), creating the workspace if n...
Con * workspace_back_and_forth_get(void)
Returns the previously focused workspace con, or NULL if unavailable.
#define NODES_FOREACH(head)
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent, bool force_set_focus)
Closes the given container including all children.
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
char * parse_string(const char **walk, bool as_word)
Parses a string (or word, if as_word is true).
void ewmh_update_current_desktop(void)
Updates _NET_CURRENT_DESKTOP with the current desktop number.
fullscreen_mode_t fullscreen_mode
#define TAILQ_NEXT(elm, field)
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
static void workspace_defer_update_urgent_hint_cb(EV_P_ ev_timer *w, int revents)
void con_detach(Con *con)
Detaches the given container from its current parent.
Con * workspace_attach_to(Con *ws)
Called when a new con (with a window, not an empty or split con) should be attached to the workspace ...
void ewmh_update_number_of_desktops(void)
Updates _NET_NUMBER_OF_DESKTOPS which we interpret as the number of noninternal workspaces.
void workspace_show(Con *workspace)
Switches to the given workspace.
char * command
Command, like in command mode.
#define GREP_FIRST(dest, head, condition)
Con * _get_sticky(Con *con, const char *sticky_group, Con *exclude)
Con * con
Pointer to the Con which represents this output.
float workspace_urgency_timer
By default, urgency is cleared immediately when switching to another workspace leads to focusing the ...
struct ws_assignments_head ws_assignments
void x_set_name(Con *con, const char *name)
Sets the WM_NAME property (so, no UTF8, but used only for debugging anyways) of the given name...
static char ** binding_workspace_names
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
#define CALL(obj, member,...)
Con * workspace_next_on_output(void)
Returns the next workspace on the same output.
int default_orientation
Default orientation for new containers.
void con_update_parents_urgency(Con *con)
Make all parent containers urgent if con is urgent or clear the urgent flag of all parent containers ...
void ipc_send_window_event(const char *property, Con *con)
For the window events we send, along the usual "change" field, also the window container, in "container".
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Con * workspace_prev(void)
Returns the previous workspace.
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
struct ev_loop * main_loop
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
void ipc_send_event(const char *event, uint32_t message_type, const char *payload)
Sends the specified event to all IPC clients which are currently connected and subscribed to this kin...
static void _workspace_show(Con *workspace)
void ewmh_update_wm_desktop(void)
Updates _NET_WM_DESKTOP for all windows.
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
A 'Con' represents everything from the X11 root window down to a single X11 window.
void x_move_win(Con *src, Con *dest)
Moves a child window from Container src to Container dest.
static bool get_urgency_flag(Con *con)
#define TAILQ_FIRST(head)
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
int con_num_children(Con *con)
Returns the number of children of this container.
void x_reparent_child(Con *con, Con *old)
Reparents the child window of the given container (necessary for sticky containers).
struct ev_timer * urgency_timer
static void _workspace_apply_default_orientation(Con *ws)
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
void workspace_back_and_forth(void)
Focuses the previously focused workspace.
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect)
Fixes the coordinates of the floating window whenever the window gets reassigned to a different outpu...
Output * get_output_by_name(const char *name)
Returns the output with the given name if it is active (!) or NULL.
void ws_force_orientation(Con *ws, orientation_t orientation)
'Forces' workspace orientation by moving all cons into a new split-con with the same orientation as t...
An Output is a physical output on your graphics driver.
bool workspace_move_to_output(Con *ws, const char *name)
Move the given workspace to the specified output.
Con * con_new(Con *parent, i3Window *window)
layout_t workspace_layout
void extract_workspace_names_from_bindings(void)
Extracts workspace names from keybindings (e.g.
#define TAILQ_PREV(elm, headname, field)
void ewmh_update_desktop_names(void)
Updates _NET_DESKTOP_NAMES: "The names of all virtual desktops.
char * name
Name of the output.
Con * workspace_encapsulate(Con *ws)
Creates a new container and re-parents all of children from the given workspace into it...
void ewmh_update_desktop_viewport(void)
Updates _NET_DESKTOP_VIEWPORT, which is an array of pairs of cardinals that define the top left corne...
void ipc_send_workspace_event(const char *change, Con *current, Con *old)
For the workspace events we send, along with the usual "change" field, also the workspace container i...
yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old)
Generates a json workspace event.
Holds a keybinding, consisting of a keycode combined with modifiers and the command which is executed...