Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/next' into gaps-next
Browse files Browse the repository at this point in the history
  • Loading branch information
orestisfl committed Oct 19, 2020
2 parents 565a8d3 + 3b2f15e commit 1b96694
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 193 deletions.
2 changes: 2 additions & 0 deletions RELEASE-NOTES-next
Expand Up @@ -46,3 +46,5 @@ working. Please reach out to us in that case!
• fix a bug with i3-nagbar not starting after it has already started once
• fix conflict when moving parent of fullscreen window to workspace
• fix Xorg memory leak with i3bar
• fix named workspace assignments on output changes
• fix named workspace assignment precedence on workspace renames
19 changes: 0 additions & 19 deletions include/handlers.h
Expand Up @@ -47,22 +47,3 @@ void handle_event(int type, xcb_generic_event_t *event);
*
*/
void property_handlers_init(void);

#if 0
/**
* Configuration notifies are only handled because we need to set up ignore
* for the following enter notify events
*
*/
int handle_configure_event(void *prophs, xcb_connection_t *conn, xcb_configure_notify_event_t *event);
#endif

#if 0
/**
* Handles _NET_WM_WINDOW_TYPE changes
*
*/
int handle_window_type(void *data, xcb_connection_t *conn, uint8_t state,
xcb_window_t window, xcb_atom_t atom,
xcb_get_property_reply_t *property);
#endif
63 changes: 14 additions & 49 deletions include/workspace.h
Expand Up @@ -45,6 +45,19 @@ Con *get_existing_workspace_by_name(const char *name);
*/
Con *get_existing_workspace_by_num(int num);

/**
* Returns the first output that is assigned to a workspace specified by the
* given name or number. Returns NULL if no such output exists.
*
* If an assignment matches by number but there is an assignment later that
* matches by name, the second one is preferred.
* The order of the 'ws_assignments' queue is respected: if multiple
* assignments match the criteria, the first one is returned.
* 'name' is ignored when NULL, 'parsed_num' is ignored when it is -1.
*
*/
Con *get_assigned_output(const char *name, long parsed_num);

/**
* Returns true if the first output assigned to a workspace with the given
* workspace assignment is the same as the given output.
Expand All @@ -57,11 +70,8 @@ bool output_triggers_assignment(Output *output, struct Workspace_Assignment *ass
* creating the workspace if necessary (by allocating the necessary amount of
* memory and initializing the data structures correctly).
*
* If created is not NULL, *created will be set to whether or not the
* workspace has just been created.
*
*/
Con *workspace_get(const char *num, bool *created);
Con *workspace_get(const char *num);

/**
* Extracts workspace names from keybindings (e.g. “web” from “bindsym $mod+1
Expand Down Expand Up @@ -136,51 +146,6 @@ void workspace_back_and_forth(void);
*/
Con *workspace_back_and_forth_get(void);

#if 0
/**
* Assigns the given workspace to the given screen by correctly updating its
* state and reconfiguring all the clients on this workspace.
*
* This is called when initializing a screen and when re-assigning it to a
* different screen which just got available (if you configured it to be on
* screen 1 and you just plugged in screen 1).
*
*/
void workspace_assign_to(Workspace *ws, Output *screen, bool hide_it);

/**
* Initializes the given workspace if it is not already initialized. The given
* screen is to be understood as a fallback, if the workspace itself either
* was not assigned to a particular screen or cannot be placed there because
* the screen is not attached at the moment.
*
*/
void workspace_initialize(Workspace *ws, Output *screen, bool recheck);

/**
* Gets the first unused workspace for the given screen, taking into account
* the preferred_screen setting of every workspace (workspace assignments).
*
*/
Workspace *get_first_workspace_for_output(Output *screen);

/**
* Unmaps all clients (and stack windows) of the given workspace.
*
* This needs to be called separately when temporarily rendering a workspace
* which is not the active workspace to force reconfiguration of all clients,
* like in src/xinerama.c when re-assigning a workspace to another screen.
*
*/
void workspace_unmap_clients(xcb_connection_t *conn, Workspace *u_ws);

/**
* Maps all clients (and stack windows) of the given workspace.
*
*/
void workspace_map_clients(xcb_connection_t *conn, Workspace *ws);
#endif

/**
* Goes through all clients on the given workspace and updates the workspace’s
* urgent flag accordingly.
Expand Down
29 changes: 6 additions & 23 deletions src/commands.c
Expand Up @@ -359,7 +359,7 @@ void cmd_move_con_to_workspace_name(I3_CMD, const char *name, const char *no_aut

LOG("should move window to workspace %s\n", name);
/* get the workspace */
Con *ws = workspace_get(name, NULL);
Con *ws = workspace_get(name);

if (no_auto_back_and_forth == NULL) {
ws = maybe_auto_back_and_forth_workspace(ws);
Expand Down Expand Up @@ -390,7 +390,7 @@ void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *no_

Con *ws = get_existing_workspace_by_num(parsed_num);
if (!ws) {
ws = workspace_get(which, NULL);
ws = workspace_get(which);
}

if (no_auto_back_and_forth == NULL) {
Expand Down Expand Up @@ -1399,7 +1399,7 @@ void cmd_focus(I3_CMD) {

CMD_FOCUS_WARN_CHILDREN;

Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
Con *__i3_scratch = workspace_get("__i3_scratch");
owindow *current;
TAILQ_FOREACH (current, &owindows, owindows) {
Con *ws = con_get_workspace(current->con);
Expand Down Expand Up @@ -2026,26 +2026,9 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
con_attach(workspace, parent, false);
ipc_send_workspace_event("rename", workspace, NULL);

/* Move the workspace to the correct output if it has an assignment */
struct Workspace_Assignment *assignment = NULL;
TAILQ_FOREACH (assignment, &ws_assignments, ws_assignments) {
if (assignment->output == NULL)
continue;
if (strcmp(assignment->name, workspace->name) != 0 && (!name_is_digits(assignment->name) || ws_name_to_number(assignment->name) != workspace->num)) {
continue;
}

Output *target_output = get_output_by_name(assignment->output, true);
if (!target_output) {
LOG("Could not get output named \"%s\"\n", assignment->output);
continue;
}
if (!output_triggers_assignment(target_output, assignment)) {
continue;
}
workspace_move_to_output(workspace, target_output);

break;
Con *assigned = get_assigned_output(workspace->name, workspace->num);
if (assigned) {
workspace_move_to_output(workspace, get_output_for_con(assigned));
}

bool can_restore_focus = previously_focused != NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/con.c
Expand Up @@ -1370,7 +1370,7 @@ bool con_move_to_mark(Con *con, const char *mark) {
}

/* For target containers in the scratchpad, we just send the window to the scratchpad. */
if (con_get_workspace(target) == workspace_get("__i3_scratch", NULL)) {
if (con_get_workspace(target) == workspace_get("__i3_scratch")) {
DLOG("target container is in the scratchpad, moving container to scratchpad.\n");
scratchpad_move(con);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers.c
Expand Up @@ -727,7 +727,7 @@ static void handle_client_message(xcb_client_message_event_t *event) {
return;
}

if (con_is_internal(ws) && ws != workspace_get("__i3_scratch", NULL)) {
if (con_is_internal(ws) && ws != workspace_get("__i3_scratch")) {
DLOG("Workspace is internal but not scratchpad, ignoring _NET_ACTIVE_WINDOW\n");
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/manage.c
Expand Up @@ -291,7 +291,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
/* A_TO_WORKSPACE type assignment or fallback from A_TO_WORKSPACE_NUMBER
* when the target workspace number does not exist yet. */
if (!assigned_ws) {
assigned_ws = workspace_get(assignment->dest.workspace, NULL);
assigned_ws = workspace_get(assignment->dest.workspace);
}

nc = con_descend_tiling_focused(assigned_ws);
Expand Down Expand Up @@ -322,7 +322,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
} else if (startup_ws) {
/* If it was started on a specific workspace, we want to open it there. */
DLOG("Using workspace on which this application was started (%s)\n", startup_ws);
nc = con_descend_tiling_focused(workspace_get(startup_ws, NULL));
nc = con_descend_tiling_focused(workspace_get(startup_ws));
DLOG("focused on ws %s: %p / %s\n", startup_ws, nc, nc->name);
if (nc->type == CT_WORKSPACE)
nc = tree_open_con(nc, cwindow);
Expand Down
44 changes: 20 additions & 24 deletions src/randr.c
Expand Up @@ -438,34 +438,29 @@ void init_ws_for_output(Output *output) {
Con *content = output_get_content(output->con);
Con *previous_focus = con_get_workspace(focused);

/* go through all assignments and move the existing workspaces to this output */
struct Workspace_Assignment *assignment;
TAILQ_FOREACH (assignment, &ws_assignments, ws_assignments) {
if (!output_triggers_assignment(output, assignment)) {
/* Iterate over all workspaces and check if any of them should be assigned
* to this output. */
Con *output_con;
TAILQ_FOREACH (output_con, &(croot->nodes_head), nodes) {
if (con_is_internal(output_con)) {
continue;
}
Con *workspace = get_existing_workspace_by_name(assignment->name);
if (workspace == NULL)
continue;

/* check that this workspace is not already attached (that means the
* user configured this assignment twice) */
Con *workspace_out = con_get_output(workspace);
if (workspace_out == output->con) {
LOG("Workspace \"%s\" assigned to output \"%s\", but it is already "
"there. Do you have two assignment directives for the same "
"workspace in your configuration file?\n",
workspace->name, output_primary_name(output));
continue;
}
Con *workspace;
TAILQ_FOREACH (workspace, &(output_get_content(output_con)->nodes_head), nodes) {
Con *workspace_out = get_assigned_output(workspace->name, workspace->num);
if (output->con != workspace_out) {
continue;
}

DLOG("Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
workspace->name, workspace_out->name, output_primary_name(output));
/* Need to copy output's rect since content is not yet rendered. We
* can't call render_con here because render_output only proceeds if a
* workspace exists. */
content->rect = output->con->rect;
workspace_move_to_output(workspace, output);
DLOG("Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
workspace->name, workspace_out->name, output_primary_name(output));
/* Need to copy output's rect since content is not yet rendered. We
* can't call render_con here because render_output only proceeds
* if a workspace exists. */
content->rect = output->con->rect;
workspace_move_to_output(workspace, output);
}
}

/* Temporarily set the focused container, might not be initialized yet. */
Expand All @@ -485,6 +480,7 @@ void init_ws_for_output(Output *output) {
}

/* otherwise, we create the first assigned ws for this output */
struct Workspace_Assignment *assignment;
TAILQ_FOREACH (assignment, &ws_assignments, ws_assignments) {
if (!output_triggers_assignment(output, assignment)) {
continue;
Expand Down
6 changes: 3 additions & 3 deletions src/scratchpad.c
Expand Up @@ -32,7 +32,7 @@ void scratchpad_move(Con *con) {
}
DLOG("should move con %p to __i3_scratch\n", con);

Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
Con *__i3_scratch = workspace_get("__i3_scratch");
if (con_get_workspace(con) == __i3_scratch) {
DLOG("This window is already on __i3_scratch.\n");
return;
Expand Down Expand Up @@ -84,7 +84,7 @@ void scratchpad_move(Con *con) {
*/
bool scratchpad_show(Con *con) {
DLOG("should show scratchpad window %p\n", con);
Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
Con *__i3_scratch = workspace_get("__i3_scratch");
Con *floating;

/* If this was 'scratchpad show' without criteria, we check if the
Expand Down Expand Up @@ -245,7 +245,7 @@ static int _lcm(const int m, const int n) {
*
*/
void scratchpad_fix_resolution(void) {
Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
Con *__i3_scratch = workspace_get("__i3_scratch");
Con *__i3_output = con_get_output(__i3_scratch);
DLOG("Current resolution: (%d, %d) %d x %d\n",
__i3_output->rect.x, __i3_output->rect.y,
Expand Down

0 comments on commit 1b96694

Please sign in to comment.