mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	action/view: Ensure view arguments are never NULL
This commit is contained in:
		
							parent
							
								
									004b817647
								
							
						
					
					
						commit
						0e6d99e0ca
					
				
					 2 changed files with 37 additions and 15 deletions
				
			
		
							
								
								
									
										16
									
								
								src/action.c
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								src/action.c
									
										
									
									
									
								
							| 
						 | 
					@ -247,18 +247,22 @@ actions_run(struct view *activator, struct server *server,
 | 
				
			||||||
			wl_display_terminate(server->wl_display);
 | 
								wl_display_terminate(server->wl_display);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case ACTION_TYPE_MOVE_TO_EDGE:
 | 
							case ACTION_TYPE_MOVE_TO_EDGE:
 | 
				
			||||||
			if (arg) {
 | 
								if (!arg) {
 | 
				
			||||||
				view_move_to_edge(view, action_str_from_arg(arg));
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				wlr_log(WLR_ERROR, "Missing argument for MoveToEdge");
 | 
									wlr_log(WLR_ERROR, "Missing argument for MoveToEdge");
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (view) {
 | 
				
			||||||
 | 
									view_move_to_edge(view, action_str_from_arg(arg));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case ACTION_TYPE_SNAP_TO_EDGE:
 | 
							case ACTION_TYPE_SNAP_TO_EDGE:
 | 
				
			||||||
			if (arg) {
 | 
								if (!arg) {
 | 
				
			||||||
 | 
									wlr_log(WLR_ERROR, "Missing argument for SnapToEdge");
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (view) {
 | 
				
			||||||
				view_snap_to_edge(view, action_str_from_arg(arg),
 | 
									view_snap_to_edge(view, action_str_from_arg(arg),
 | 
				
			||||||
					/*store_natural_geometry*/ true);
 | 
										/*store_natural_geometry*/ true);
 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				wlr_log(WLR_ERROR, "Missing argument for SnapToEdge");
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case ACTION_TYPE_NEXT_WINDOW:
 | 
							case ACTION_TYPE_NEXT_WINDOW:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										36
									
								
								src/view.c
									
										
									
									
									
								
							
							
						
						
									
										36
									
								
								src/view.c
									
										
									
									
									
								
							| 
						 | 
					@ -116,7 +116,6 @@ void
 | 
				
			||||||
view_set_activated(struct view *view)
 | 
					view_set_activated(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	assert(view);
 | 
						assert(view);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct view *last = view->server->focused_view;
 | 
						struct view *last = view->server->focused_view;
 | 
				
			||||||
	if (last == view) {
 | 
						if (last == view) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -131,6 +130,7 @@ view_set_activated(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_close(struct view *view)
 | 
					view_close(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	if (view->impl->close) {
 | 
						if (view->impl->close) {
 | 
				
			||||||
		view->impl->close(view);
 | 
							view->impl->close(view);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -139,6 +139,7 @@ view_close(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_move(struct view *view, int x, int y)
 | 
					view_move(struct view *view, int x, int y)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	if (view->impl->move) {
 | 
						if (view->impl->move) {
 | 
				
			||||||
		view->impl->move(view, x, y);
 | 
							view->impl->move(view, x, y);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -147,6 +148,7 @@ view_move(struct view *view, int x, int y)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_moved(struct view *view)
 | 
					view_moved(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	wlr_scene_node_set_position(&view->scene_tree->node, view->x, view->y);
 | 
						wlr_scene_node_set_position(&view->scene_tree->node, view->x, view->y);
 | 
				
			||||||
	view_discover_output(view);
 | 
						view_discover_output(view);
 | 
				
			||||||
	ssd_update_geometry(view);
 | 
						ssd_update_geometry(view);
 | 
				
			||||||
| 
						 | 
					@ -157,6 +159,7 @@ view_moved(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_move_resize(struct view *view, struct wlr_box geo)
 | 
					view_move_resize(struct view *view, struct wlr_box geo)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	if (view->impl->configure) {
 | 
						if (view->impl->configure) {
 | 
				
			||||||
		view->impl->configure(view, geo);
 | 
							view->impl->configure(view, geo);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -178,6 +181,7 @@ round_to_increment(int val, int base, int inc)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_adjust_size(struct view *view, int *w, int *h)
 | 
					view_adjust_size(struct view *view, int *w, int *h)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	int min_width = MIN_VIEW_WIDTH;
 | 
						int min_width = MIN_VIEW_WIDTH;
 | 
				
			||||||
	int min_height = MIN_VIEW_HEIGHT;
 | 
						int min_height = MIN_VIEW_HEIGHT;
 | 
				
			||||||
#if HAVE_XWAYLAND
 | 
					#if HAVE_XWAYLAND
 | 
				
			||||||
| 
						 | 
					@ -208,6 +212,7 @@ view_adjust_size(struct view *view, int *w, int *h)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_minimize(struct view *view, bool minimized)
 | 
					view_minimize(struct view *view, bool minimized)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	if (view->minimized == minimized) {
 | 
						if (view->minimized == minimized) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -240,6 +245,7 @@ view_minimize(struct view *view, bool minimized)
 | 
				
			||||||
struct wlr_output *
 | 
					struct wlr_output *
 | 
				
			||||||
view_wlr_output(struct view *view)
 | 
					view_wlr_output(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	double closest_x, closest_y;
 | 
						double closest_x, closest_y;
 | 
				
			||||||
	struct wlr_output *wlr_output = NULL;
 | 
						struct wlr_output *wlr_output = NULL;
 | 
				
			||||||
	wlr_output_layout_closest_point(view->server->output_layout, wlr_output,
 | 
						wlr_output_layout_closest_point(view->server->output_layout, wlr_output,
 | 
				
			||||||
| 
						 | 
					@ -312,6 +318,7 @@ set_fallback_geometry(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_store_natural_geometry(struct view *view)
 | 
					view_store_natural_geometry(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * If an application was started maximized or fullscreened, its
 | 
						 * If an application was started maximized or fullscreened, its
 | 
				
			||||||
	 * natural_geometry width/height may still be zero in which case we set
 | 
						 * natural_geometry width/height may still be zero in which case we set
 | 
				
			||||||
| 
						 | 
					@ -330,6 +337,7 @@ view_store_natural_geometry(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_center(struct view *view)
 | 
					view_center(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	int x, y;
 | 
						int x, y;
 | 
				
			||||||
	if (view_compute_centered_position(view, view->w, view->h, &x, &y)) {
 | 
						if (view_compute_centered_position(view, view->w, view->h, &x, &y)) {
 | 
				
			||||||
		view_move(view, x, y);
 | 
							view_move(view, x, y);
 | 
				
			||||||
| 
						 | 
					@ -444,6 +452,7 @@ set_maximized(struct view *view, bool maximized)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_restore_to(struct view *view, struct wlr_box geometry)
 | 
					view_restore_to(struct view *view, struct wlr_box geometry)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	if (view->fullscreen) {
 | 
						if (view->fullscreen) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -456,6 +465,7 @@ view_restore_to(struct view *view, struct wlr_box geometry)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_maximize(struct view *view, bool maximize, bool store_natural_geometry)
 | 
					view_maximize(struct view *view, bool maximize, bool store_natural_geometry)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	if (view->maximized == maximize) {
 | 
						if (view->maximized == maximize) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -487,6 +497,7 @@ view_maximize(struct view *view, bool maximize, bool store_natural_geometry)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_toggle_maximize(struct view *view)
 | 
					view_toggle_maximize(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	view_maximize(view, !view->maximized,
 | 
						view_maximize(view, !view->maximized,
 | 
				
			||||||
		/*store_natural_geometry*/ true);
 | 
							/*store_natural_geometry*/ true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -494,6 +505,7 @@ view_toggle_maximize(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_toggle_decorations(struct view *view)
 | 
					view_toggle_decorations(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	view_set_decorations(view, !view->ssd.enabled);
 | 
						view_set_decorations(view, !view->ssd.enabled);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -507,6 +519,7 @@ is_always_on_top(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_toggle_always_on_top(struct view *view)
 | 
					view_toggle_always_on_top(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	if (is_always_on_top(view)) {
 | 
						if (is_always_on_top(view)) {
 | 
				
			||||||
		view->workspace = view->server->workspace_current;
 | 
							view->workspace = view->server->workspace_current;
 | 
				
			||||||
		wlr_scene_node_reparent(&view->scene_tree->node, view->workspace->tree);
 | 
							wlr_scene_node_reparent(&view->scene_tree->node, view->workspace->tree);
 | 
				
			||||||
| 
						 | 
					@ -519,6 +532,7 @@ view_toggle_always_on_top(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_set_decorations(struct view *view, bool decorations)
 | 
					view_set_decorations(struct view *view, bool decorations)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	if (view->ssd.enabled != decorations && !view->fullscreen) {
 | 
						if (view->ssd.enabled != decorations && !view->fullscreen) {
 | 
				
			||||||
		view->ssd.enabled = decorations;
 | 
							view->ssd.enabled = decorations;
 | 
				
			||||||
		ssd_update_geometry(view);
 | 
							ssd_update_geometry(view);
 | 
				
			||||||
| 
						 | 
					@ -533,6 +547,7 @@ view_set_decorations(struct view *view, bool decorations)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_toggle_fullscreen(struct view *view)
 | 
					view_toggle_fullscreen(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	view_set_fullscreen(view, !view->fullscreen, NULL);
 | 
						view_set_fullscreen(view, !view->fullscreen, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -540,6 +555,7 @@ void
 | 
				
			||||||
view_set_fullscreen(struct view *view, bool fullscreen,
 | 
					view_set_fullscreen(struct view *view, bool fullscreen,
 | 
				
			||||||
		struct wlr_output *wlr_output)
 | 
							struct wlr_output *wlr_output)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	if (fullscreen != !view->fullscreen) {
 | 
						if (fullscreen != !view->fullscreen) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -590,6 +606,7 @@ view_set_fullscreen(struct view *view, bool fullscreen,
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_adjust_for_layout_change(struct view *view)
 | 
					view_adjust_for_layout_change(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	struct wlr_output_layout *layout = view->server->output_layout;
 | 
						struct wlr_output_layout *layout = view->server->output_layout;
 | 
				
			||||||
	if (view->fullscreen) {
 | 
						if (view->fullscreen) {
 | 
				
			||||||
		if (wlr_output_layout_get(layout, view->fullscreen)) {
 | 
							if (wlr_output_layout_get(layout, view->fullscreen)) {
 | 
				
			||||||
| 
						 | 
					@ -640,6 +657,7 @@ view_output_leave(struct view *view, struct wlr_output *wlr_output)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_discover_output(struct view *view)
 | 
					view_discover_output(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	struct output *old_output = view->output;
 | 
						struct output *old_output = view->output;
 | 
				
			||||||
	struct output *new_output = view_output(view);
 | 
						struct output *new_output = view_output(view);
 | 
				
			||||||
	if (old_output != new_output) {
 | 
						if (old_output != new_output) {
 | 
				
			||||||
| 
						 | 
					@ -656,6 +674,7 @@ view_discover_output(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_on_output_destroy(struct view *view)
 | 
					view_on_output_destroy(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	view_output_leave(view, view->output->wlr_output);
 | 
						view_output_leave(view, view->output->wlr_output);
 | 
				
			||||||
	view->output = NULL;
 | 
						view->output = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -663,10 +682,7 @@ view_on_output_destroy(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_move_to_edge(struct view *view, const char *direction)
 | 
					view_move_to_edge(struct view *view, const char *direction)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!view) {
 | 
						assert(view);
 | 
				
			||||||
		wlr_log(WLR_ERROR, "no view");
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	struct output *output = view_output(view);
 | 
						struct output *output = view_output(view);
 | 
				
			||||||
	if (!output) {
 | 
						if (!output) {
 | 
				
			||||||
		wlr_log(WLR_ERROR, "no output");
 | 
							wlr_log(WLR_ERROR, "no output");
 | 
				
			||||||
| 
						 | 
					@ -733,10 +749,7 @@ void
 | 
				
			||||||
view_snap_to_edge(struct view *view, const char *direction,
 | 
					view_snap_to_edge(struct view *view, const char *direction,
 | 
				
			||||||
		bool store_natural_geometry)
 | 
							bool store_natural_geometry)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!view) {
 | 
						assert(view);
 | 
				
			||||||
		wlr_log(WLR_ERROR, "no view");
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (view->fullscreen) {
 | 
						if (view->fullscreen) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -800,6 +813,8 @@ view_snap_to_edge(struct view *view, const char *direction,
 | 
				
			||||||
const char *
 | 
					const char *
 | 
				
			||||||
view_get_string_prop(struct view *view, const char *prop)
 | 
					view_get_string_prop(struct view *view, const char *prop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
 | 
						assert(prop);
 | 
				
			||||||
	if (view->impl->get_string_prop) {
 | 
						if (view->impl->get_string_prop) {
 | 
				
			||||||
		return view->impl->get_string_prop(view, prop);
 | 
							return view->impl->get_string_prop(view, prop);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -809,6 +824,7 @@ view_get_string_prop(struct view *view, const char *prop)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_update_title(struct view *view)
 | 
					view_update_title(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	const char *title = view_get_string_prop(view, "title");
 | 
						const char *title = view_get_string_prop(view, "title");
 | 
				
			||||||
	if (!view->toplevel_handle || !title) {
 | 
						if (!view->toplevel_handle || !title) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -820,6 +836,7 @@ view_update_title(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_update_app_id(struct view *view)
 | 
					view_update_app_id(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	const char *app_id = view_get_string_prop(view, "app_id");
 | 
						const char *app_id = view_get_string_prop(view, "app_id");
 | 
				
			||||||
	if (!view->toplevel_handle || !app_id) {
 | 
						if (!view->toplevel_handle || !app_id) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -831,6 +848,7 @@ view_update_app_id(struct view *view)
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_destroy(struct view *view)
 | 
					view_destroy(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						assert(view);
 | 
				
			||||||
	struct server *server = view->server;
 | 
						struct server *server = view->server;
 | 
				
			||||||
	bool need_cursor_update = false;
 | 
						bool need_cursor_update = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue