How to Programmatically Switch to a Specific Window in Compiz

How to programmatically switch to a specific window in compiz?

What you are looking for is wmctrl.
For example, add a keyboard shortcut to invoke a command like

wmctrl -Fa 'Wiki - Google Chrome'

to raise and activate the window with that title.

There are different ways of selecting a window by title, id, etc. See man wmctrl.
The list of windows can be obtained running

$ wmctrl -l

I haven't tried it with compiz but wmctrl should work for any EWMH compliant window manager.

Gnome - shortcut to switch through instances of one application

If you Alt+Tab to nautilus and wait 1sec (or hit down arrow) it will pop up all instances and you can "arrow navigate" them.

OR

Alt+Tab and when you reach to nautilus hit alt+` (key above tab)

How to move window offscreen with wmctrl

When running under a window manager, this is entirely up to the window manager. Whether there is a flag to force partial off-screen positions depends on which window manager it is.

The only window manager agnostic way of achieving this is making the window an override_redirect window. But, of course, this means the window is no longer managed. Making it a normal window again will cause the window manager to manage it again which likely, again depending on the window manager, means forcing it to be in-bounds again.

That said, looking at wmctrl's source code, it uses _NET_MOVERESIZE_WINDOW if supported by the window manager and falls back to XMoveResizeWindow (or similar) otherwise. However, in the first case it casts the position values to unsigned long first which effectively means any negative values will be lost anyway. In the second case, negative values seem to signal "don't move", so no luck there either.

You could try using xdotool windowmove instead which will deal with negative values correctly. Maybe also consider filing a bug against wmctrl?

How could i detect info for the front most window in X?

To find out the window ID, try:

xprop -root|grep "_NET_CLIENT_LIST_STACKING(WINDOW): window id"

Window properties:

_NET_CLIENT_LIST_STACKING has bottom-to-top stacking order

One way to accomplish this is to parse the output of this command inside your application. The topmost window is the last on the list.

EDIT:

If you need to retrieve the process ID from the window ID, there's a small application here that shows how to do this trick. I successfully compiled it with:

g++ win_procid.cpp -o win_procid -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libgtop-2.0 -lXtst -lgtop-2.0

I had to install the package libgtop2-dev because I didn't have it on my system.

Set foreground window for Windows program running under Wine

You can use X11 window manager xdotool or X window manager wmctrl.

Consider the following scenario. A MS windows application titled WordWeb Installer running in wine on Ubuntu on workspace 2. Current workspace : 1. To switch to workspace 2 and focus the wine app execute

wmctrl -R wordweb or

xdotool windowactivate $( xdotool search --name wordweb )

How configure VirtualBox shortcuts to switch between virtual computer and host with single key combination on windows 10

Does one of these works for you:

  • Host key + m, minimize virtualbox os window,
  • Click Host key once and release to let the vm lose focus, then Alt + Tab, switch to a window of residing os,

Tips:

  • The Host key is used to transfer focus to residing os, on windows or linux it's right Ctrl by default.
  • If the vm already lose focus, then you don't need to press the Host key first, otherwise you need to press once & release, to transfer focus back to residing os.
  • If you switch back to the vm again via Alt + Tab, then vm will get focus again, then to get back to residing os, you need to press Host key again.


The virtualbox Auto Capture Keyboard option

(from File -> Preference -> Input).

Behavior:

  • If checked, then you need Host key to return focus to residing os, just as described above.
  • If unchecked, then vm is just treated as a simple window in host. You can use Alt + Tab to switch to a window from host anytime, without press the Host key first. But, you also can't switch within windows inside the vm, via Alt + Tab any more.

Which to use:

There is a trade off, it depends on what you use the vm for to decide whether check it or not.

In my case:

  • When I am using Windows vm on a Linux host.

    In the Windows vm browser with proxy is the only thing I need most of the time, and most of the time I am on Linux host.

    So I uncheck it, so that never need to click Host key to get back to Linux host.
  • When I am using Linux vm on a Windows host.

    Actually most of the time I am working on the linux vm, and sometimes need to go to the Windows host.

    So I check it, so that I can switch between windows of Linux vm via Alt + Tab, and when I need to go back to Windows host, I click Host key first or use mouse.

How to make a window always on top?

the EWMH specification explicitly states that:

_NET_WM_STATE_ABOVE and _NET_WM_STATE_BELOW are mainly meant for user preferences and should not be used by applications e.g. for drawing attention to their dialogs (the Urgency hint should be used in that case, see the section called “Urgency”).

so window managers have no responsibility to respect applications which set this property directly (i.e by XChangeProperty) by themselves. this property can be changed only by sending a client message to the root window
which window managers listens on.

i don't know how to do it in high-level gui toolkits like Qt, but here is how to do it in plain X11.(see EWMH spec, or _wnck_change_state for a sample implementation).

//file: test.c
//to build it, run
//shell> gcc test.c -lX11

#include <X11/Xlib.h>

#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
#define _NET_WM_STATE_ADD 1 /* add/set property */
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */

// change a window's _NET_WM_STATE property so that it can be kept on top.
// @display: x11 display singleton.
// @xid : the window to set on top.
Status x11_window_set_on_top (Display* display, Window xid)
{
XEvent event;
event.xclient.type = ClientMessage;
event.xclient.serial = 0;
event.xclient.send_event = True;
event.xclient.display = display;
event.xclient.window = xid;
event.xclient.message_type = XInternAtom (display, "_NET_WM_STATE", False);
event.xclient.format = 32;

event.xclient.data.l[0] = _NET_WM_STATE_ADD;
event.xclient.data.l[1] = XInternAtom (display, "_NET_WM_STATE_ABOVE", False);
event.xclient.data.l[2] = 0; //unused.
event.xclient.data.l[3] = 0;
event.xclient.data.l[4] = 0;

return XSendEvent (display, DefaultRootWindow(display), False,
SubstructureRedirectMask|SubstructureNotifyMask, &event);
}

// a sample main function for testing.
// shell> ./a.out window_xid
int main (int argc, char** argv)
{
Window xid = strtol (argv[1], NULL, 0);
Display* display = XOpenDisplay (NULL);

x11_window_set_on_top (display, xid);

XFlush (display); //for simplicity, no event loops here.

XCloseDisplay (display);
}

also note that in some x11 environment(e.g. compiz), system menus are provided by a separate decorator program instead of the compositing window manager.

How do you run an application in bash and select which monitor it runs on?

If you run separate displays on each monitor (less likely these days), the DISPLAY environment variable is what you want.

If you use Xinerama (spreading one logical display across multiple monitors), however:

  • Aside: X11 vocabulary: A "display" is one or more "screens" with input devices; e.g. keyboard and mouse, a.k.a. a "seat." A "screen" is a logical canvas that is partially or completely displayed on one or more "monitors;" when using multiple monitors for one "screen," the windows can be partially displayed on each monitor, but share the same X11 DISPLAY identifier; this is called Xinerama. The DISPLAY format is host : display-number . screen-id, so e.g. on my Xinerama set-up both monitors are part of screen 0 on a display number that counts up from 0 with each logged-in user on the same host. "Seats" are logical groups of monitor+input that are using different hardware; multiple "displays" can occur using "virtual console" switching, which is how Gnome and KDE allow multiple users to sign in on a single "seat" machine.

Most GUI toolkits allow you to specify the window's geometry using the --geometry or -geometry switch.

  • Qt uses the older MIT-style -geometry form. GTK+/Gnome uses the GNU-style --geometry.

  • This assumes that you're allowing Qt to post-process your command-line, e.g. passing argv into QtApplication or similar.

The “logical display” will have a resolution which is the sum of the resolutions in each direction of the arrangement of your monitors. For example, I have 2 × 1920×1080 displays hooked up right now. xrandr reports:

Screen 0: minimum 320 x 200, current 3840 x 1080, maximum 8192 x 8192

To display a window on the right-hand monitor, I can give a geometry string that has its x co-ordinates between 1920…3839 (inclusive).

The usual format is: width x height ± x-offset ± y-offset ­­— but the width and height are optional, if you prefer to take the defaults. The ± are + to count relative to the top/left, or - to count relative to the bottom/right.

So, for example:

gedit --geometry 800x600+1920+0  # set size at top-left of right screen
gedit --geometry +1920+100 # default size at top-left of right screen
gedit --geometry -0+0 # default size at top-right of entire display

Unfortunately, the only programmatic way I know of to determine the area of the display on each monitor from the shell would be to parse the output from xrandr; e.g.

$ xrandr
Screen 0: minimum 320 x 200, current 3840 x 1080, maximum 8192 x 8192
LVDS1 connected (normal left inverted right x axis y axis)
1366x768 60.0 +
1024x768 60.0
800x600 60.3 56.2
640x480 59.9
VGA1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 510mm x 287mm
1920x1080 60.0*+
1680x1050 60.0
1280x1024 60.0
1440x900 59.9
1280x720 60.0
1024x768 60.0
800x600 60.3
640x480 60.0
720x400 70.1
HDMI1 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 510mm x 287mm
1920x1080 60.0*+
1680x1050 59.9
1280x1024 60.0
1440x900 59.9
1280x720 60.0
1024x768 60.0
800x600 60.3
640x480 60.0
720x400 70.1
DP1 disconnected (normal left inverted right x axis y axis)

$ xrandr | perl -ne 'if (/(\d+)x(\d+)\+(\d+)\+(\d+)/) '\
> ' { print "$3,$4 - ", $3 + $1 - 1, ",", $4 + $2 - 1, "\n" }'
0,0 - 1919,1079
1920,0 - 3839,1079

(You'd normally want to avoid splitting the Perl one-liner across two lines in the shell, but the '\' trick there is to make it legible on SO.)



Related Topics



Leave a reply



Submit