diff --git a/include/data.h b/include/data.h index 9a814f45..374a70fb 100644 --- a/include/data.h +++ b/include/data.h @@ -569,6 +569,8 @@ struct Con { /** callbacks */ void(*on_remove_child)(Con *); + /** not a scratchpad window, auto centered scratchpad window, or + * user positioned scratchpad window. */ enum { SCRATCHPAD_NONE = 0, SCRATCHPAD_FRESH = 1, diff --git a/src/commands.c b/src/commands.c index 6179e750..2404a811 100644 --- a/src/commands.c +++ b/src/commands.c @@ -592,6 +592,10 @@ static void cmd_resize_floating(I3_CMD, char *way, char *direction, Con *floatin } else if (strcmp(direction, "left") == 0) { floating_con->rect.x -= (floating_con->rect.width - old_rect.width); } + + /* If this is a scratchpad window, don't auto center it from now on. */ + if (floating_con->scratchpad_state == SCRATCHPAD_FRESH) + floating_con->scratchpad_state = SCRATCHPAD_CHANGED; } static bool cmd_resize_tiling_direction(I3_CMD, Con *current, char *way, char *direction, int ppt) { diff --git a/src/floating.c b/src/floating.c index 66fdeac4..4dd44f57 100644 --- a/src/floating.c +++ b/src/floating.c @@ -438,6 +438,11 @@ void floating_drag_window(Con *con, const xcb_button_press_event_t *event) { /* Drag the window */ drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, XCURSOR_CURSOR_MOVE, drag_window_callback, event); + + /* If this is a scratchpad window, don't auto center it from now on. */ + if (con->scratchpad_state == SCRATCHPAD_FRESH) + con->scratchpad_state = SCRATCHPAD_CHANGED; + tree_render(); } @@ -537,6 +542,10 @@ void floating_resize_window(Con *con, const bool proportional, struct resize_window_callback_params params = { corner, proportional, event }; drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, cursor, resize_window_callback, ¶ms); + + /* If this is a scratchpad window, don't auto center it from now on. */ + if (con->scratchpad_state == SCRATCHPAD_FRESH) + con->scratchpad_state = SCRATCHPAD_CHANGED; } /* @@ -660,6 +669,11 @@ void floating_reposition(Con *con, Rect newrect) { con->rect = newrect; floating_maybe_reassign_ws(con); + + /* If this is a scratchpad window, don't auto center it from now on. */ + if (con->scratchpad_state == SCRATCHPAD_FRESH) + con->scratchpad_state = SCRATCHPAD_CHANGED; + tree_render(); } diff --git a/src/scratchpad.c b/src/scratchpad.c index bca44e59..a4d29505 100644 --- a/src/scratchpad.c +++ b/src/scratchpad.c @@ -178,7 +178,6 @@ void scratchpad_show(Con *con) { ((output->rect.width / 2.0) - (con->rect.width / 2.0)); con->rect.y = output->rect.y + ((output->rect.height / 2.0) - (con->rect.height / 2.0)); - con->scratchpad_state = SCRATCHPAD_CHANGED; } /* Activate active workspace if window is from another workspace to ensure diff --git a/testcases/t/185-scratchpad.t b/testcases/t/185-scratchpad.t index d3994300..6ee877bd 100644 --- a/testcases/t/185-scratchpad.t +++ b/testcases/t/185-scratchpad.t @@ -93,8 +93,7 @@ is(scalar @{$__i3_scratch->{floating_nodes}}, 0, '__i3_scratch ws empty'); ################################################################################ # 3: Verify that 'scratchpad toggle' sends a window to the __i3_scratch # workspace and sets the scratchpad flag to SCRATCHPAD_FRESH. The window’s size -# and position will be changed (once!) on the next 'scratchpad show' and the -# flag will be changed to SCRATCHPAD_CHANGED. +# and position will be changed on the next 'scratchpad show'. ################################################################################ my ($nodes, $focus) = get_ws_content($tmp); @@ -165,10 +164,33 @@ $__i3_scratch = get_ws('__i3_scratch'); @scratch_nodes = @{$__i3_scratch->{floating_nodes}}; is(scalar @scratch_nodes, 1, '__i3_scratch contains our window'); -is($scratch_nodes[0]->{scratchpad_state}, 'changed', 'scratchpad_state changed'); +################################################################################ +# 6: Resizing the window should disable auto centering on scratchpad show +################################################################################ + +cmd 'scratchpad show'; + +$ws = get_ws($tmp); +is($ws->{floating_nodes}->[0]->{scratchpad_state}, 'fresh', + 'scratchpad_state fresh'); + +cmd 'resize grow width 10 px'; +cmd 'scratchpad show'; +cmd 'scratchpad show'; + +$ws = get_ws($tmp); +$scratchrect = $ws->{floating_nodes}->[0]->{rect}; +$outputrect = $output->{rect}; + +is($ws->{floating_nodes}->[0]->{scratchpad_state}, 'changed', + 'scratchpad_state changed'); +is($scratchrect->{width}, $outputrect->{width} * 0.5 + 10, 'scratch width is 50% + 10px'); + +cmd 'resize shrink width 10 px'; +cmd 'scratchpad show'; ################################################################################ -# 6: Verify that repeated 'scratchpad show' cycle through the stack, that is, +# 7: Verify that repeated 'scratchpad show' cycle through the stack, that is, # toggling a visible window should insert it at the bottom of the stack of the # __i3_scratch workspace. ################################################################################