Codebase list i3-gaps / fae10f6
allow ppt values in move direction and move position commands make ppt values clear in userguide chore: move is_ppt and DLOG out of TAILQ_FOREACH loop acheronfail 3 years ago
6 changed file(s) with 94 addition(s) and 55 deletion(s). Raw diff Collapse all Expand all
2626 • update i3bar config when necessary (reduces redraws on bar mode changes)
2727 • mention rofi in default config file
2828 • i3-input: add different exit codes for when i3-input fails
29 • allow ppt values in move direction and move position commands
2930
3031 ┌────────────────────────────┐
3132 │ Bugfixes │
244244
245245 So, how can you open a new terminal window to the *right* of the current one?
246246 The solution is to use +focus parent+, which will focus the +Parent Container+ of
247 the current +Container+. In default configuration, use +$mod+a+ to navigate one
247 the current +Container+. In default configuration, use +$mod+a+ to navigate one
248248 +Container+ up the tree (you can repeat this multiple times until you get to the
249249 +Workspace Container+). In this case, you would focus the +Vertical Split Container+
250250 which is *inside* the horizontally oriented workspace. Thus, now new windows will be
14141414 Scroll wheel right.
14151415 button7::
14161416 Scroll wheel left.
1417
1417
14181418
14191419 Please note that the old +wheel_up_cmd+ and +wheel_down_cmd+ commands are deprecated
14201420 and will be removed in a future release. We strongly recommend using the more general
16811681 the form "[n][:][NAME]" will display only the number.
16821682
16831683 The default is to display the full name within the workspace button. Be aware
1684 that the colon in the workspace name is optional, so `[n][NAME]` will also
1685 have the workspace name and number stripped correctly.
1684 that the colon in the workspace name is optional, so `[n][NAME]` will also
1685 have the workspace name and number stripped correctly.
16861686
16871687 *Syntax*:
16881688 ------------------------------
21392139 # Moves the container into the given direction.
21402140 # The optional pixel argument specifies how far the
21412141 # container should be moved if it is floating and
2142 # defaults to 10 pixels.
2143 move <left|right|down|up> [<px> px]
2142 # defaults to 10 pixels. The optional ppt argument
2143 # means "percentage points", and if specified it indicates
2144 # how many points the container should be moved if it is
2145 # floating rather than by a pixel value.
2146 move <left|right|down|up> [<amount> [px|ppt]]
21442147
21452148 # Moves the container to the specified pos_x and pos_y
21462149 # coordinates on the screen.
2147 move position <pos_x> [px] <pos_y> [px]
2150 move position <pos_x> [px|ppt] <pos_y> [px|ppt]
21482151
21492152 # Moves the container to the center of the screen.
21502153 # If 'absolute' is used, it is moved to the center of
218218 void cmd_sticky(I3_CMD, const char *action);
219219
220220 /**
221 * Implementation of 'move <direction> [<pixels> [px]]'.
222 *
223 */
224 void cmd_move_direction(I3_CMD, const char *direction_str, long move_px);
221 * Implementation of 'move <direction> [<amount> [px|ppt]]'.
222 *
223 */
224 void cmd_move_direction(I3_CMD, const char *direction_str, long amount, const char *mode);
225225
226226 /**
227227 * Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
266266 void cmd_focus_output(I3_CMD, const char *name);
267267
268268 /**
269 * Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px]
270 *
271 */
272 void cmd_move_window_to_position(I3_CMD, long x, long y);
269 * Implementation of 'move [window|container] [to] [absolute] position [<pos_x> [px|ppt] <pos_y> [px|ppt]]
270 *
271 */
272 void cmd_move_window_to_position(I3_CMD, long x, const char *mode_x, long y, const char *mode_y);
273273
274274 /**
275275 * Implementation of 'move [window|container] [to] [absolute] position center
130130 -> call cmd_workspace_back_and_forth()
131131 'number'
132132 -> WORKSPACE_NUMBER
133 workspace = string
133 workspace = string
134134 -> call cmd_workspace_name($workspace, $no_auto_back_and_forth)
135135
136136 state WORKSPACE_NUMBER:
320320 new_name = string
321321 -> call cmd_rename_workspace($old_name, $new_name)
322322
323 # move <direction> [<pixels> [px]]
323
324 # move <direction> [<amount> [px|ppt]]
324325 # move [window|container] [to] workspace [<str>|next|prev|next_on_output|prev_on_output|current]
325326 # move [window|container] [to] output <str>
326327 # move [window|container] [to] mark <str>
327328 # move [window|container] [to] scratchpad
328329 # move workspace to [output] <str>
329330 # move scratchpad
330 # move [window|container] [to] [absolute] position [ [<pixels> [px] <pixels> [px]] | center ]
331 # move [window|container] [to] [absolute] position [ [<pos_x> [px|ppt] <pos_y> [px|ppt] ] | center ]
331332 # move [window|container] [to] position mouse|cursor|pointer
332333 state MOVE:
333334 'window'
354355 -> MOVE_TO_ABSOLUTE_POSITION
355356
356357 state MOVE_DIRECTION:
357 pixels = number
358 -> MOVE_DIRECTION_PX
359 end
360 -> call cmd_move_direction($direction, 10)
361
362 state MOVE_DIRECTION_PX:
363 'px'
364 -> call cmd_move_direction($direction, &pixels)
365 end
366 -> call cmd_move_direction($direction, &pixels)
358 amount = number
359 -> MOVE_DIRECTION_NUMBER
360 end
361 -> call cmd_move_direction($direction, 10, "px")
362
363 state MOVE_DIRECTION_NUMBER:
364 mode = 'px', 'ppt'
365 -> call cmd_move_direction($direction, &amount, $mode)
366 end
367 -> call cmd_move_direction($direction, &amount, "px")
367368
368369 state MOVE_WORKSPACE:
369370 'to '
408409 -> MOVE_TO_POSITION_X
409410
410411 state MOVE_TO_POSITION_X:
411 'px'
412 mode_x = 'px', 'ppt'
412413 ->
413414 coord_y = number
414415 -> MOVE_TO_POSITION_Y
415416
416417 state MOVE_TO_POSITION_Y:
417 'px', end
418 -> call cmd_move_window_to_position(&coord_x, &coord_y)
418 mode_y = 'px', 'ppt'
419 -> call cmd_move_window_to_position(&coord_x, $mode_x, &coord_y, $mode_y)
420 end
421 -> call cmd_move_window_to_position(&coord_x, $mode_x, &coord_y, 0)
419422
420423 # mode <string>
421424 state MODE:
14891489 }
14901490
14911491 /*
1492 * Implementation of 'move <direction> [<pixels> [px]]'.
1493 *
1494 */
1495 void cmd_move_direction(I3_CMD, const char *direction_str, long move_px) {
1492 * Implementation of 'move <direction> [<amount> [px|ppt]]'.
1493 *
1494 */
1495 void cmd_move_direction(I3_CMD, const char *direction_str, long amount, const char *mode) {
14961496 owindow *current;
14971497 HANDLE_EMPTY_MATCH;
14981498
14991499 Con *initially_focused = focused;
15001500 direction_t direction = parse_direction(direction_str);
15011501
1502 TAILQ_FOREACH (current, &owindows, owindows) {
1503 DLOG("moving in direction %s, px %ld\n", direction_str, move_px);
1502 const bool is_ppt = mode && strcmp(mode, "ppt") == 0;
1503
1504 DLOG("moving in direction %s, %ld %s\n", direction_str, amount, mode);
1505 TAILQ_FOREACH (current, &owindows, owindows) {
15041506 if (con_is_floating(current->con)) {
1505 DLOG("floating move with %ld pixels\n", move_px);
1507 DLOG("floating move with %ld %s\n", amount, mode);
15061508 Rect newrect = current->con->parent->rect;
1509 Con *output = con_get_output(current->con);
15071510
15081511 switch (direction) {
15091512 case D_LEFT:
1510 newrect.x -= move_px;
1513 newrect.x -= is_ppt ? output->rect.width * ((double)amount / 100.0) : amount;
15111514 break;
15121515 case D_RIGHT:
1513 newrect.x += move_px;
1516 newrect.x += is_ppt ? output->rect.width * ((double)amount / 100.0) : amount;
15141517 break;
15151518 case D_UP:
1516 newrect.y -= move_px;
1519 newrect.y -= is_ppt ? output->rect.height * ((double)amount / 100.0) : amount;
15171520 break;
15181521 case D_DOWN:
1519 newrect.y += move_px;
1522 newrect.y += is_ppt ? output->rect.height * ((double)amount / 100.0) : amount;
15201523 break;
15211524 }
15221525
17201723 }
17211724
17221725 /*
1723 * Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px]
1724 *
1725 */
1726 void cmd_move_window_to_position(I3_CMD, long x, long y) {
1726 * Implementation of 'move [window|container] [to] [absolute] position [<pos_x> [px|ppt] <pos_y> [px|ppt]]
1727 *
1728 */
1729 void cmd_move_window_to_position(I3_CMD, long x, const char *mode_x, long y, const char *mode_y) {
17271730 bool has_error = false;
17281731
17291732 owindow *current;
17421745 }
17431746
17441747 Rect newrect = current->con->parent->rect;
1745
1746 DLOG("moving to position %ld %ld\n", x, y);
1747 newrect.x = x;
1748 newrect.y = y;
1748 Con *output = con_get_output(current->con);
1749
1750 newrect.x = mode_x && strcmp(mode_x, "ppt") == 0 ? output->rect.width * ((double)x / 100.0) : x;
1751 newrect.y = mode_y && strcmp(mode_y, "ppt") == 0 ? output->rect.height * ((double)y / 100.0) : y;
1752 DLOG("moving to position %d %s %d %s\n", newrect.x, mode_x, newrect.y, mode_y);
17491753
17501754 if (!floating_reposition(current->con->parent, newrect)) {
17511755 yerror("Cannot move window/container out of bounds.");
219219 is($absolute->width, $absolute_before->width, 'width not changed');
220220 is($absolute->height, $absolute_before->height, 'height not changed');
221221
222 ######################################################################
223 # 6) test moving floating window to a specified position
222 $absolute_before = $absolute;
223 $top_before = $top;
224
225 ######################################################################
226 # 7) test moving floating containers with a specific amount of ppt
227 ######################################################################
228
229 cmd 'move right 25 ppt';
230
231 sync_with_i3;
232
233 ($absolute, $top) = $floatwin->rect;
234
235 is($absolute->x, int($x->root->rect->width * 0.25) + $absolute_before->x, 'moved 25 ppt to the right');
236 is($absolute->y, $absolute_before->y, 'y not changed');
237 is($absolute->width, $absolute_before->width, 'width not changed');
238 is($absolute->height, $absolute_before->height, 'height not changed');
239
240 ######################################################################
241 # 8) test moving floating window to a specified position
224242 # and to absolute center
225243 ######################################################################
226244
227245 $tmp = fresh_workspace;
228246 open_floating_window; my @floatcon;
229247
248 # Move to specified position with px
230249 cmd 'move position 5 px 15 px';
231250
232251 @floatcon = @{get_ws($tmp)->{floating_nodes}};
233252
234 is($floatcon[0]->{rect}->{x}, 5, 'moved to position 5 x');
235 is($floatcon[0]->{rect}->{y}, 15, 'moved to position 15 y');
236
253 is($floatcon[0]->{rect}->{x}, 5, 'moved to position 5 (px) x');
254 is($floatcon[0]->{rect}->{y}, 15, 'moved to position 15 (px) y');
255
256 # Move to specified position with ppt
257 cmd 'move position 20 ppt 20 ppt';
258
259 @floatcon = @{get_ws($tmp)->{floating_nodes}};
260
261 is($floatcon[0]->{rect}->{x}, int($x->root->rect->width * 0.20), "moved to position 20 (ppt) x");
262 is($floatcon[0]->{rect}->{y}, int($x->root->rect->height * 0.20), "moved to position 20 (ppt) y");
263
264 # Move to absolute center
237265 cmd 'move absolute position center';
238266
239267 @floatcon = @{get_ws($tmp)->{floating_nodes}};