how to bring application to front with xdg-open - linux

On linux, xdg-open can launch an application, but in most cases the desired behavior is to only launch the application if it's not already running, and to bring it to the front if it is already running.
Can xdg-open do this? Is there some other standard way to provide this functionality?

As you can see xdg-open is nothing more then the wrapper which handles the file type and opens it in the preferred application. It's up to the application if it does or doesn't support "bring to front" option.
$ file /usr/bin/xdg-open
/usr/bin/xdg-open: POSIX shell script, ASCII text executable
In order to bring to front the application window you might use other tools like wmctrl, xdotool or qdbus.
Details:
NAME
wmctrl - interact with a EWMH/NetWM compatible X Window Manager.
SYNOPSIS
wmctrl [ options | actions ]...
DESCRIPTION
wmctrl is a command that can be used to interact with an X Window man‐
ager that is compatible with the EWMH/NetWM specification. wmctrl can
query the window manager for information, and it can request that cer‐
tain window management actions be taken.
[...]
-a <WIN>
Switch to the desktop containing the window <WIN>, raise the
window, and give it focus.
NAME
xdotool - command-line X11 automation tool
SYNOPSIS
xdotool cmd args...
Notation: Some documentation uses [window] to denote an optional window
argument. This case means that the argument, if not present, will
default to "%1". See "WINDOW STACK" for what "%1" means.
DESCRIPTION
xdotool lets you programatically (or manually) simulate keyboard input
and mouse activity, move and resize windows, etc. It does this using
X11's XTEST extension and other Xlib functions.
There is some support for Extended Window Manager Hints (aka EWMH or
NetWM). See the "EXTENDED WINDOW MANAGER HINTS" section for more
information.

Related

kde 'window shortcuts' are temporary

I'm running the KDE desktop, and I'd like to associate hotkeys with a set of windows and use those hotkeys to activate those windows from anywhere. Ideally, this would work like in Windows - where the key launches the app the first time you press it, and thereafter just brings it to the front. But I don't think that's possible in KDE (why not???).
Anyway, the kwin window menu has a "More Actions/Window Shortcut" option that does let you set a key combination that will bring that window to the front. Except that it only works for the current session. Is there no way to make that association permanent?
In my normal Windows workspace, I have 2 PuTty sessions logged on to a unix host under different user ids. Each of these has an associated hotkey. In addition, I have the app I work in (a browser of sorts) with its own hotkey, and a programming editor with its own key. I am constantly switching between these 4 windows, and I do it all with keystrokes. And I use the same keystrokes to start those sessions up when I first need them. It's great - the only Windows feature that I seriously miss when running Linux. How can I come closest to having that in KDE? Or some other Linux desktop?
Well, I tried xdotool, and combined in a script and attached to a KDE custom shortcut, it actually works. Launches the app if xdotool doesn't find it, and activates the window if it does. Painful, but it does work. The app in question is WIN32 code - hence launching it via wine.
Here's the script:
#!/bin/bash
pid=`xdotool search --name Medialine`
if [ "$pid" == "" ]; then
wine /home/rob/wem.exe&
else
xdotool windowactivate $pid
fi

How to manipulate a window in Linux

I've been programming in Linux for years but don't have too much knowledge in the perspective of display. Now I'm asked to write a separate process that will monitor which window (probably not the window created by my process) is focused by the user and do some simple manipulations such as move and resize.
Is it possible? Is there a general way to achieve that? Can someone give any hint I can look into? Thanks!
Use xdotool. It can emulate keystrokes, mouse-actions, find active windows etc.
Example: Run this command in your (non maximized) terminal window and it will jump 10 pixels down and to the right:
xdotool windowmove --relative $(xdotool getwindowfocus) 10 10
It should be available in most distributions, ie sudo apt-get install xdotool or similar for other package managers.
Essentially its the XWindow system that does it all. However you can control a lot of it using simple utilities. For example if I wan to change the title of a VLC window, I can do it like this:
# this will ask me to point to a window and I will point to VLC player
$ xwininfo -all | grep 'xwininfo: Window id:'
xwininfo: Window id: 0x2000011 (has no name)
Here 0x2000011 is the window id of VLC Player running on my system. We can use this window to get or set properties. To do that we can use xprop utility:
for p in _NET_WM_VISIBLE_NAME _NET_WM_NAME; \
do xprop -id 0x2000011 -format $p 8s -set $p "MyVLC"; done
This will change the window title of VLC Player to MyVLC.
Although this is what xdotool also does behind the scenes, these commands are fairly low level, and are very likely be installed by default.
References:
https://github.com/ChickenProp/set-window-title/blob/master/set-window-title

Can't write English in xterm terminal

My keyboard has two languages, English and other. But in xterm I can write only in other language, and I can't replace the language in any way (alt-lshift, the regular way, or in the gui). With shift key I can write upper case (with caps lock it doesn’t work).
The Cygwin guides on the internet referrals me to xkb layout files, that doesn't existing in my computer at all.
I open the xterm from the icon of Xwin.
Thank you.
Since this is an XTerm running in the Cygwin X server, the X server is doing all the keyboard input translation, independently from the keyboard translation Windows does for other programs (the X server reads the raw keyboard input from the device). So you have to use the X11 methods of changing keyboard layouts. Into your .xinitrc or .xprofile (I can't remember which one Cygwin uses) put the following command
setxkbmap us
To load the US keyboard layout. You can type it also from your xterm when you need it. Read the manpage of setxbmap for details.

Terminal emulator with good plugin support?

Is there any good linux terminal emulator that supports plugins?
What I am after:
Open source
Being able to highlight and color text fragments
Being able to tweak the GUI (create popup windows, present menus and buttons integrated with the text display -- for instance to open the man page in a floating window when clicking on a command name)
Being able to write plugins in a number of languages (Ruby preferred)
Cheers!
All that I found:
termit - extensible via lua
rxvt-unicode - extensible via perl

Is there a way to specify the window offset for an app spawned in X?

I am writing a bash script that calls some apps that run in their own window. However, they appear at a standard position on the screen. I want to be able to specify the screen co-ordinates where they appear.
Is there a setting that can be passed in command line to make this happen? I am presently using openbox and if this is a window manager feature that openbox cannot provide, could anyone recommend another lightweight window manager (fluxbox?) to which I can specify window offsets?
Is there an X setting that can do this for me?
Many X clients support a -geometry argument (sometimes --geometry) which allows you to specify size and/or position of the initial window.
devilspie could be of help you can specify different window properties on compliant window managers.
Some examples are also available.

Resources