mirror of
https://github.com/labwc/labwc.git
synced 2026-04-10 08:21:07 -04:00
...based on https://github.com/johanmalm/checkpatch.pl ``` src/server.c:161: ERROR: space required before the open parenthesis '(' src/server.c:473: CHECK: Blank lines aren't necessary after an open brace '{' src/desktop.c:228: WARNING: function definition argument 'struct wl_list *' should also have an identifier name src/output.c:289: CHECK: Blank lines aren't necessary before a close brace '}' src/interactive.c:20: WARNING: suspect code indent for conditional statements (8, 17) src/interactive.c:27: WARNING: Statements should start on a tabstop src/config/rcxml.c:607: CHECK: Blank lines aren't necessary after an open brace '{' src/config/rcxml.c:638: CHECK: line length of 91 exceeds 90 columns src/config/rcxml.c:639: CHECK: Blank lines aren't necessary after an open brace '{' src/debug.c:126: WARNING: suspect code indent for conditional statements (8, 24) src/debug.c:129: WARNING: suspect code indent for conditional statements (8, 24) src/view.c:307: CHECK: Please use a blank line after function/struct/union/enum declarations src/workspaces.c:52: CHECK: Blank lines aren't necessary after an open brace '{' src/workspaces.c:147: ERROR: space prohibited before that close parenthesis ')' src/workspaces.c:226: CHECK: line length of 91 exceeds 90 columns src/workspaces.c:290: CHECK: Please don't use multiple blank lines src/workspaces.c:328: WARNING: else is not generally useful after a break or return src/cursor.c:18: ERROR: do not initialise statics to NULL src/cursor.c:20: CHECK: Please don't use multiple blank lines src/common/scaled_font_buffer.c:55: CHECK: Assignment operator '=' should be on the previous line src/common/graphic-helpers.c:44: CHECK: Blank lines aren't necessary after an open brace '{' src/common/graphic-helpers.c:71: CHECK: multiple assignments should be avoided src/common/scaled_scene_buffer.c:115: CHECK: Assignment operator '=' should be on the previous line src/common/scaled_scene_buffer.c:135: CHECK: Assignment operator '=' should be on the previous line src/common/fd_util.c:15: CHECK: line length of 106 exceeds 90 columns src/common/fd_util.c:22: CHECK: line length of 106 exceeds 90 columns src/common/fd_util.c:25: ERROR: code indent should use tabs where possible src/common/fd_util.c:25: WARNING: please, no spaces at the start of a line include/workspaces.h:13: ERROR: code indent should use tabs where possible include/workspaces.h:13: WARNING: Block comments use * on subsequent lines include/workspaces.h:13: WARNING: Block comments use a trailing */ on a separate line include/workspaces.h:20: CHECK: Please don't use multiple blank lines include/workspaces.h:26: ERROR: "foo * bar" should be "foo *bar" include/action.h:11: ERROR: code indent should use tabs where possible include/action.h:12: ERROR: code indent should use tabs where possible include/action.h:12: WARNING: Block comments use a trailing */ on a separate line include/common/scaled_scene_buffer.h:62: CHECK: Please don't use multiple blank lines ```
140 lines
4.2 KiB
C
140 lines
4.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
#include "labwc.h"
|
|
|
|
static int
|
|
max_move_scale(double pos_cursor, double pos_current,
|
|
double size_current, double size_orig)
|
|
{
|
|
double anchor_frac = (pos_cursor - pos_current) / size_current;
|
|
int pos_new = pos_cursor - (size_orig * anchor_frac);
|
|
if (pos_new < pos_current) {
|
|
/* Clamp by using the old offsets of the maximized window */
|
|
pos_new = pos_current;
|
|
}
|
|
return pos_new;
|
|
}
|
|
|
|
void
|
|
interactive_begin(struct view *view, enum input_mode mode, uint32_t edges)
|
|
{
|
|
if (mode == LAB_INPUT_STATE_MOVE && view->fullscreen) {
|
|
/**
|
|
* We don't allow moving fullscreen windows.
|
|
*
|
|
* If you think there is a good reason to allow it
|
|
* feel free to open an issue explaining your use-case.
|
|
*/
|
|
return;
|
|
}
|
|
if (mode == LAB_INPUT_STATE_RESIZE
|
|
&& (view->fullscreen || view->maximized)) {
|
|
/* We don't allow resizing while in maximized or fullscreen state */
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* This function sets up an interactive move or resize operation, where
|
|
* the compositor stops propagating pointer events to clients and
|
|
* instead consumes them itself, to move or resize windows.
|
|
*/
|
|
struct seat *seat = &view->server->seat;
|
|
struct server *server = view->server;
|
|
server->grabbed_view = view;
|
|
server->input_mode = mode;
|
|
|
|
/* Remember view and cursor positions at start of move/resize */
|
|
server->grab_x = seat->cursor->x;
|
|
server->grab_y = seat->cursor->y;
|
|
server->grab_box.x = view->x;
|
|
server->grab_box.y = view->y;
|
|
server->grab_box.width = view->w;
|
|
server->grab_box.height = view->h;
|
|
server->resize_edges = edges;
|
|
|
|
if (view->maximized || view->tiled) {
|
|
if (mode == LAB_INPUT_STATE_MOVE) {
|
|
/* Exit maximized or tiled mode */
|
|
int new_x = max_move_scale(view->server->seat.cursor->x,
|
|
view->x, view->w, view->natural_geometry.width);
|
|
int new_y = max_move_scale(view->server->seat.cursor->y,
|
|
view->y, view->h, view->natural_geometry.height);
|
|
view->natural_geometry.x = new_x;
|
|
view->natural_geometry.y = new_y;
|
|
if (view->maximized) {
|
|
view_maximize(view, false);
|
|
}
|
|
if (view->tiled) {
|
|
view_move_resize(view, view->natural_geometry);
|
|
}
|
|
/**
|
|
* view_maximize() / view_move_resize() indirectly calls
|
|
* view->impl->configure which is async but we are using
|
|
* the current values in server->grab_box. We pretend the
|
|
* configure already happened by setting them manually.
|
|
*/
|
|
server->grab_box.x = new_x;
|
|
server->grab_box.y = new_y;
|
|
server->grab_box.width = view->natural_geometry.width;
|
|
server->grab_box.height = view->natural_geometry.height;
|
|
}
|
|
}
|
|
|
|
/* Moving or resizing always resets tiled state */
|
|
view->tiled = 0;
|
|
|
|
switch (mode) {
|
|
case LAB_INPUT_STATE_MOVE:
|
|
cursor_set(&server->seat, LAB_CURSOR_GRAB);
|
|
break;
|
|
case LAB_INPUT_STATE_RESIZE:
|
|
cursor_set(&server->seat, cursor_get_from_edge(edges));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void
|
|
interactive_end(struct view *view)
|
|
{
|
|
if (view->server->grabbed_view == view) {
|
|
bool should_snap = view->server->input_mode == LAB_INPUT_STATE_MOVE
|
|
&& rc.snap_edge_range;
|
|
view->server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
|
|
view->server->grabbed_view = NULL;
|
|
if (should_snap) {
|
|
int snap_range = rc.snap_edge_range;
|
|
struct wlr_box *area = &view->output->usable_area;
|
|
|
|
/* Translate into output local coordinates */
|
|
double cursor_x = view->server->seat.cursor->x;
|
|
double cursor_y = view->server->seat.cursor->y;
|
|
wlr_output_layout_output_coords(view->server->output_layout,
|
|
view->output->wlr_output, &cursor_x, &cursor_y);
|
|
|
|
if (cursor_x <= area->x + snap_range) {
|
|
view_snap_to_edge(view, "left");
|
|
} else if (cursor_x >= area->x + area->width - snap_range) {
|
|
view_snap_to_edge(view, "right");
|
|
} else if (cursor_y <= area->y + snap_range) {
|
|
if (rc.snap_top_maximize) {
|
|
view_maximize(view, true);
|
|
/*
|
|
* When unmaximizing later on restore
|
|
* original position
|
|
*/
|
|
view->natural_geometry.x =
|
|
view->server->grab_box.x;
|
|
view->natural_geometry.y =
|
|
view->server->grab_box.y;
|
|
} else {
|
|
view_snap_to_edge(view, "up");
|
|
}
|
|
} else if (cursor_y >= area->y + area->height - snap_range) {
|
|
view_snap_to_edge(view, "down");
|
|
}
|
|
}
|
|
/* Update focus/cursor image */
|
|
cursor_update_focus(view->server);
|
|
}
|
|
}
|