LAB_SSD_PREF_SERVER,
};
+enum view_edge {
+ VIEW_EDGE_INVALID = 0,
+
+ VIEW_EDGE_LEFT,
+ VIEW_EDGE_RIGHT,
+ VIEW_EDGE_UP,
+ VIEW_EDGE_DOWN,
+ VIEW_EDGE_CENTER,
+};
+
struct view;
struct view_impl {
void (*configure)(struct view *view, struct wlr_box geo);
void view_set_decorations(struct view *view, bool decorations);
void view_toggle_fullscreen(struct view *view);
void view_adjust_for_layout_change(struct view *view);
-void view_move_to_edge(struct view *view, const char *direction);
-void view_snap_to_edge(struct view *view, const char *direction,
- bool store_natural_geometry);
-void view_snap_to_region(struct view *view, struct region *region,
- bool store_natural_geometry);
+void view_move_to_edge(struct view *view, enum view_edge direction);
+void view_snap_to_edge(struct view *view, enum view_edge direction, bool store_natural_geometry);
+void view_snap_to_region(struct view *view, struct region *region, bool store_natural_geometry);
void view_move_to_front(struct view *view);
void view_move_to_back(struct view *view);
void view_on_output_destroy(struct view *view);
void view_destroy(struct view *view);
+enum view_edge view_edge_parse(const char *direction);
+
/* xdg.c */
struct wlr_xdg_surface *xdg_surface_from_view(struct view *view);
case ACTION_TYPE_MOVE_TO_EDGE:
case ACTION_TYPE_SNAP_TO_EDGE:
if (!strcmp(argument, "direction")) {
- action_arg_add_str(action, argument, content);
+ enum view_edge edge = view_edge_parse(content);
+ if ((edge == VIEW_EDGE_CENTER && action->type != ACTION_TYPE_SNAP_TO_EDGE)
+ || edge == VIEW_EDGE_INVALID) {
+ wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)",
+ action_names[action->type], argument, content);
+ } else {
+ action_arg_add_int(action, argument, edge);
+ }
goto cleanup;
}
break;
break;
case ACTION_TYPE_MOVE_TO_EDGE:
if (view) {
- view_move_to_edge(view, action_str_from_arg(arg));
+ /* Config parsing makes sure that direction is a valid direction */
+ enum view_edge edge = get_arg_value_int(action, "direction", 0);
+ view_move_to_edge(view, edge);
}
break;
case ACTION_TYPE_SNAP_TO_EDGE:
if (view) {
- view_snap_to_edge(view, action_str_from_arg(arg),
- /*store_natural_geometry*/ true);
+ /* Config parsing makes sure that direction is a valid direction */
+ enum view_edge edge = get_arg_value_int(action, "direction", 0);
+ view_snap_to_edge(view, edge, /*store_natural_geometry*/ true);
}
break;
case ACTION_TYPE_NEXT_WINDOW:
*/
struct wlr_box *area = &view->output->usable_area;
if (cursor_x <= area->x + snap_range) {
- view_snap_to_edge(view, "left",
+ view_snap_to_edge(view, VIEW_EDGE_LEFT,
/*store_natural_geometry*/ false);
} else if (cursor_x >= area->x + area->width - snap_range) {
- view_snap_to_edge(view, "right",
+ view_snap_to_edge(view, VIEW_EDGE_RIGHT,
/*store_natural_geometry*/ false);
} else if (cursor_y <= area->y + snap_range) {
if (rc.snap_top_maximize) {
view_maximize(view, true,
/*store_natural_geometry*/ false);
} else {
- view_snap_to_edge(view, "up",
+ view_snap_to_edge(view, VIEW_EDGE_UP,
/*store_natural_geometry*/ false);
}
} else if (cursor_y >= area->y + area->height - snap_range) {
- view_snap_to_edge(view, "down",
+ view_snap_to_edge(view, VIEW_EDGE_DOWN,
/*store_natural_geometry*/ false);
} else {
/* Not close to any edge */
* They may be called repeatably during output layout changes.
*/
-enum view_edge {
- VIEW_EDGE_INVALID = 0,
-
- VIEW_EDGE_LEFT,
- VIEW_EDGE_RIGHT,
- VIEW_EDGE_UP,
- VIEW_EDGE_DOWN,
- VIEW_EDGE_CENTER,
-};
-
static enum view_edge
view_edge_invert(enum view_edge edge)
{
}
void
-view_move_to_edge(struct view *view, const char *direction)
+view_move_to_edge(struct view *view, enum view_edge edge)
{
assert(view);
struct output *output = view->output;
wlr_log(WLR_ERROR, "view has no output, not moving to edge");
return;
}
- if (!direction) {
- wlr_log(WLR_ERROR, "invalid edge, not moving view");
- return;
- }
struct border margin = ssd_get_margin(view->ssd);
struct wlr_box usable = output_usable_area_in_layout_coords(output);
}
int x = 0, y = 0;
- if (!strcasecmp(direction, "left")) {
+ switch (edge) {
+ case VIEW_EDGE_LEFT:
x = usable.x + margin.left + rc.gap;
y = view->pending.y;
- } else if (!strcasecmp(direction, "up")) {
+ break;
+ case VIEW_EDGE_UP:
x = view->pending.x;
y = usable.y + margin.top + rc.gap;
- } else if (!strcasecmp(direction, "right")) {
+ break;
+ case VIEW_EDGE_RIGHT:
x = usable.x + usable.width - view->pending.width
- margin.right - rc.gap;
y = view->pending.y;
- } else if (!strcasecmp(direction, "down")) {
+ break;
+ case VIEW_EDGE_DOWN:
x = view->pending.x;
y = usable.y + usable.height - view->pending.height
- margin.bottom - rc.gap;
- } else {
- wlr_log(WLR_ERROR, "invalid edge, not moving view");
+ break;
+ default:
return;
}
view_move(view, x, y);
}
-static enum view_edge
+enum view_edge
view_edge_parse(const char *direction)
{
if (!direction) {
}
void
-view_snap_to_edge(struct view *view, const char *direction,
- bool store_natural_geometry)
+view_snap_to_edge(struct view *view, enum view_edge edge, bool store_natural_geometry)
{
assert(view);
if (view->fullscreen) {
wlr_log(WLR_ERROR, "view has no output, not snapping to edge");
return;
}
- enum view_edge edge = view_edge_parse(direction);
- if (edge == VIEW_EDGE_INVALID) {
- wlr_log(WLR_ERROR, "invalid edge, not snapping view");
- return;
- }
if (view->tiled == edge && !view->maximized) {
/* We are already tiled for this edge and thus should switch outputs */