Exemplo n.º 1
0
Arquivo: focus.c Projeto: fvwmorg/fvwm
/*
 *
 * Moves focus to specified window; only to be called bay Focus and FlipFocus
 *
 */
static void __activate_window_by_command(
	F_CMD_ARGS, int is_focus_by_flip_focus_cmd)
{
	int cx;
	int cy;
	Bool do_not_warp;
	sftfwin_args_t sf_args;
	FvwmWindow * const fw = exc->w.fw;

	memset(&sf_args, 0, sizeof(sf_args));
	sf_args.do_allow_force_broadcast = 1;
	sf_args.is_focus_by_flip_focus_cmd = is_focus_by_flip_focus_cmd;
	sf_args.set_by = FOCUS_SET_BY_FUNCTION;
        sf_args.client_entered = 0;
	if (fw == NULL || !FP_DO_FOCUS_BY_FUNCTION(FW_FOCUS_POLICY(fw)))
	{
		UngrabEm(GRAB_NORMAL);
		if (fw)
		{
			/* give the window a chance to take the focus itself */
			sf_args.do_forbid_warp = 1;
			sf_args.do_force = 0;
			set_focus_to_fwin(FW_W(fw), fw, &sf_args);
		}
		return;
	}

	do_not_warp = StrEquals(PeekToken(action, NULL), "NoWarp");
	if (!do_not_warp)
	{
		if (fw->Desk != Scr.CurrentDesk)
		{
			goto_desk(fw->Desk);
		}
		if (IS_ICONIFIED(fw))
		{
			rectangle g;
			Bool rc;

			rc = get_visible_icon_title_geometry(fw, &g);
			if (rc == False)
			{
				get_visible_icon_picture_geometry(fw, &g);
			}
			cx = g.x + g.width / 2;
			cy = g.y + g.height / 2;
		}
		else
		{
			cx = fw->g.frame.x + fw->g.frame.width/2;
			cy = fw->g.frame.y + fw->g.frame.height/2;
		}
		if (
			cx < 0 || cx >= Scr.MyDisplayWidth ||
			cy < 0 || cy >= Scr.MyDisplayHeight)
		{
			int dx;
			int dy;

			dx = ((cx + Scr.Vx) / Scr.MyDisplayWidth) *
				Scr.MyDisplayWidth;
			dy = ((cy + Scr.Vy) / Scr.MyDisplayHeight) *
				Scr.MyDisplayHeight;
			MoveViewport(dx, dy, True);
		}
#if 0 /* can not happen */
		/* If the window is still not visible, make it visible! */
		if (fw->g.frame.x + fw->g.frame.width < 0 ||
		    fw->g.frame.y + fw->g.frame.height < 0 ||
		    fw->g.frame.x >= Scr.MyDisplayWidth ||
		    fw->g.frame.y >= Scr.MyDisplayHeight)
		{
			frame_setup_window(
				fw, 0, 0, fw->g.frame.width,
				fw->g.frame.height, False);
			if (
				FP_DO_WARP_POINTER_ON_FOCUS_FUNC(
					FW_FOCUS_POLICY(fw)))
			{
				FWarpPointerUpdateEvpos(
					exc->x.elast, dpy, None, Scr.Root, 0,
					0, 0, 0, 2, 2);
			}
		}
#endif
	}
	UngrabEm(GRAB_NORMAL);

	if (fw->Desk == Scr.CurrentDesk)
	{
		FvwmWindow *sf;

		sf = get_focus_window();
		sf_args.do_forbid_warp = !!do_not_warp;
		sf_args.do_force = 0;
                sf_args.client_entered = 0;
		set_focus_to_fwin(FW_W(fw), fw, &sf_args);
		if (sf != get_focus_window())
		{
			/* Ignore EnterNotify event while we are waiting for
			 * this window to be focused. */
			Scr.focus_in_pending_window = sf;
		}
	}

	return;
}
Exemplo n.º 2
0
Arquivo: focus.c Projeto: fvwmorg/fvwm
void CMD_WarpToWindow(F_CMD_ARGS)
{
	int val1_unit, val2_unit, n;
	int val1, val2;
	int do_raise;
	char *next;
	char *token;

	next = GetNextToken(action, &token);
	if (StrEquals(token, "!raise"))
	{
		do_raise = 0;
		action = next;
	}
	else if (StrEquals(token, "raise"))
	{
		do_raise = 1;
		action = next;
	}
	else
	{
		do_raise = 1;
	}
	n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit);
	if (exc->w.wcontext != C_UNMANAGED)
	{
		if (n == 2)
		{
			warp_to_fvwm_window(
				exc, val1, val1_unit, val2, val2_unit,
				do_raise);
		}
		else
		{
			warp_to_fvwm_window(exc, 0, 0, 0, 0, do_raise);
		}
	}
	else
	{
		int x = 0;
		int y = 0;

		if (n == 2)
		{
			int wx;
			int wy;
			int ww;
			int wh;

			if (!XGetGeometry(
				    dpy, exc->w.w, &JunkRoot, &wx, &wy,
				    (unsigned int*)&ww, (unsigned int*)&wh,
				    (unsigned int*)&JunkBW,
				    (unsigned int*)&JunkDepth))
			{
				return;
			}
			if (val1_unit != Scr.MyDisplayWidth)
			{
				x = val1;
			}
			else
			{
				x = (ww - 1) * val1 / 100;
			}
			if (val2_unit != Scr.MyDisplayHeight)
			{
				y = val2;
			}
			else
			{
				y = (wh - 1) * val2 / 100;
			}
			if (x < 0)
			{
				x += ww;
			}
			if (y < 0)
			{
				y += wh;
			}
		}
		FWarpPointerUpdateEvpos(
			exc->x.elast, dpy, None, exc->w.w, 0, 0, 0, 0, x, y);
	}

	return;
}
Exemplo n.º 3
0
Arquivo: focus.c Projeto: fvwmorg/fvwm
/*
 *
 * Moves pointer to specified window
 *
 */
static void warp_to_fvwm_window(
	const exec_context_t *exc, int warp_x, int x_unit, int warp_y,
	int y_unit, int do_raise)
{
	int dx,dy;
	int cx,cy;
	int x,y;
	FvwmWindow *t = exc->w.fw;

	if (t == (FvwmWindow *)0 ||
	    (IS_ICONIFIED(t) && FW_W_ICON_TITLE(t) == None))
	{
		return;
	}
	if (t->Desk != Scr.CurrentDesk)
	{
		goto_desk(t->Desk);
	}
	if (IS_ICONIFIED(t))
	{
		rectangle g;
		Bool rc;

		rc = get_visible_icon_title_geometry(t, &g);
		if (rc == False)
		{
			get_visible_icon_picture_geometry(t, &g);
		}
		cx = g.x + g.width / 2;
		cy = g.y + g.height / 2;
	}
	else
	{
		cx = t->g.frame.x + t->g.frame.width/2;
		cy = t->g.frame.y + t->g.frame.height/2;
	}
	dx = (cx + Scr.Vx) / Scr.MyDisplayWidth * Scr.MyDisplayWidth;
	dy = (cy + Scr.Vy) / Scr.MyDisplayHeight * Scr.MyDisplayHeight;
	if (dx != Scr.Vx || dy != Scr.Vy)
	{
		MoveViewport(dx, dy, True);
	}
	if (IS_ICONIFIED(t))
	{
		rectangle g;
		Bool rc;

		rc = get_visible_icon_title_geometry(t, &g);
		if (rc == False)
		{
			get_visible_icon_picture_geometry(t, &g);
		}
		x = g.x + g.width / 2;
		y = g.y + g.height / 2;
	}
	else
	{
		if (x_unit != Scr.MyDisplayWidth && warp_x >= 0)
		{
			x = t->g.frame.x + warp_x;
		}
		else if (x_unit != Scr.MyDisplayWidth)
		{
			x = t->g.frame.x + t->g.frame.width + warp_x;
		}
		else if (warp_x >= 0)
		{
			x = t->g.frame.x +
				(t->g.frame.width - 1) * warp_x / 100;
		}
		else
		{
			x = t->g.frame.x +
				(t->g.frame.width - 1) * (100 + warp_x) / 100;
		}

		if (y_unit != Scr.MyDisplayHeight && warp_y >= 0)
		{
			y = t->g.frame.y + warp_y;
		}
		else if (y_unit != Scr.MyDisplayHeight)
		{
			y = t->g.frame.y + t->g.frame.height + warp_y;
		}
		else if (warp_y >= 0)
		{
			y = t->g.frame.y +
				(t->g.frame.height - 1) * warp_y / 100;
		}
		else
		{
			y = t->g.frame.y +
				(t->g.frame.height - 1) * (100 + warp_y) / 100;
		}
	}
	FWarpPointerUpdateEvpos(
		exc->x.elast, dpy, None, Scr.Root, 0, 0, 0, 0, x, y);
	if (do_raise)
	{
		RaiseWindow(t, False);
	}
	/* If the window is still not visible, make it visible! */
	if (t->g.frame.x + t->g.frame.width  < 0 ||
	    t->g.frame.y + t->g.frame.height < 0 ||
	    t->g.frame.x >= Scr.MyDisplayWidth ||
	    t->g.frame.y >= Scr.MyDisplayHeight)
	{
		frame_setup_window(
			t, 0, 0, t->g.frame.width, t->g.frame.height, False);
		FWarpPointerUpdateEvpos(
			exc->x.elast, dpy, None, Scr.Root, 0, 0, 0, 0, 2, 2);
	}

	return;
}
Exemplo n.º 4
0
void CMD_WarpToWindow(F_CMD_ARGS)
{
	int val1_unit, val2_unit, n;
	int val1, val2;
	struct monitor *m;
	int do_raise;
	char *next;
	char *token;

	next = GetNextToken(action, &token);
	if (StrEquals(token, "!raise"))
	{
		do_raise = 0;
		action = next;
	}
	else if (StrEquals(token, "raise"))
	{
		do_raise = 1;
		action = next;
	}
	else
	{
		do_raise = 1;
	}
	n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit);
	if (exc->w.wcontext != C_UNMANAGED)
	{
		if (n == 2)
		{
			warp_to_mvwm_window(
				exc, val1, val1_unit, val2, val2_unit,
				do_raise);
		}
		else
		{
			warp_to_mvwm_window(exc, 0, 0, 0, 0, do_raise);
		}
	}
	else
	{
		int x = 0;
		int y = 0;

		if (n == 2)
		{
			int wx;
			int wy;
			int ww;
			int wh;

			if (exc->w.w == None || !XGetGeometry(
				    dpy, exc->w.w, &JunkRoot, &wx, &wy,
				    (unsigned int*)&ww, (unsigned int*)&wh,
				    (unsigned int*)&JunkBW,
				    (unsigned int*)&JunkDepth))
			{
				return;
			}

			/* TA:  2014-09-11:  This window is unmanaged.  Since
			 * mvwm won't have created a window for this, fw will be
			 * NULL and hence no monitor information will be
			 * present.  Since we already know the coordinates of
			 * the unmanaged window, use those in determining the
			 * monitor to use.
			 */
			m = monitor_by_xy(wx, wy);

			if (val1_unit != m->coord.w)
			{
				x = val1;
			}
			else
			{
				x = (ww - 1) * val1 / 100;
			}
			if (val2_unit != m->coord.h)
			{
				y = val2;
			}
			else
			{
				y = (wh - 1) * val2 / 100;
			}
			if (x < 0)
			{
				x += ww;
			}
			if (y < 0)
			{
				y += wh;
			}
		}
		FWarpPointerUpdateEvpos(
			exc->x.elast, dpy, None, exc->w.w, 0, 0, 0, 0, x, y);
	}

	return;
}