Controlling placement of non-x utility programs using xinit - linux

Just getting started with linux programming and X Windows in specific. I am trying to make an application where I launch 4 different programs (such as VLC, web browser etc) in a quadrant view. For now I don't need (or want) an window manager sitting on top, just the bare bones applications running.
I can do this with the x utils (like a clock etc) using the -geometry commands.
My question is, how do I control the placement of these other applications?

Solution 1
devilspie is the perfect tool for this. As an example:
+--------+------------------------+
| Pidgin | |
| Buddy | Pidgin |
| List | Conversation |
| | |
| +------------------------+
| | |
| | Xchat |
| | |
| | |
+--------+------------------------+
could be done with the following configuration.
(if (is (application_name) "Pidgin")
(begin
(if (is (window_role) "buddy_list")
(begin
(undecorate)
(skip_tasklist)
(geometry "199x767+0+0")
)
)
(if (is (window_role) "conversation")
(begin
(undecorate)
(geometry "822x400+201+0")
)
)
)
)
Solution 2
start the desired applications and then use wmctrl to move and resize the windows to their desired positions. You may use the -r argument to acheive this.
-r <WIN> -e <MVARG> Resize and move the window around the desktop.
Devilspie experience (update)
As requested in the comment. I use devilspie all the time, it's really great and works with every window manager I've used gnome, xfce, kde, fvwm. I've put together a working devilspie config that will do part of what you want. You can place this file in ~/.devilspie/devilspie.ds. There is a screenshot attached as well showing the result of this config file. The best documentation I have found for devilspie is on foosel.org. I highly recommend you use that. when testing devilspie run it in the foreground in a terminal. Make sure there are no other devilspie process running kill them if so. Every time you change your config and want to see the result do a CTRL+C on the devilspie and run it again. Some other things to keep note of if vlc was maximized when it was closed, then it will open again maximized and will ignore devilspie requests for resizing and moving. So make sure vlc is not maximized when you close it. You could alternatively call unmaximize and then do the geometry call.
(debug)
(if
(is (application_name) "VLC media player")
(geometry "500x300+0+0")
)
(if
(is (application_name) "xterm")
(geometry "300x300+510+0")
)
(focus)
screetshot

Related

Automatically use desired monitor and the corresponding audio ouput

I'm using manjaro-linux-i3 with polybar and I'm currently working on my multiple monitor setup.
I have a TV which I normally use with the amplifier it is connected to. In addition I have my desk with a triple monitor setup which I normally use with my headphones for audio output. One of my screens is in portrait orientation which always messes up my login screen.
I'm able to change my audio ouput and my active monitor as I wish. But I want it to be more efficient. At the moment I'm using arandr to change my monitor and pavucontrol to change my audio output when needed.
I want that my login manager(lightdm) is always displayed correctly on my monitors(even on the portrait one).
It would be nice if anybody could give me way how to combine changing monitors and the audio output in one blow. So that I don't have to this every time manually.
I have similar setup and I got everything working what you might want if I understood you corretely.
If you setup everything right, then your loginmanager should always be displayed on the monitor which is active at boot and you can switch your monitors&sink with a simple keybind.
First, you can add a script to lightdm to config your monitors so that everything is displayed correctely. But be aware that a broken script can leed to the effect that your loginmanager won't be loaded correctly (blackscrren).
in /etc/lightdm/lightdm.conf you can define a script at #greeter-setup-script= . Simply uncomment the line and add the path to your script.
An easy way to config your monitors the way you want is to use arandr. Simply config your monitor the ways you want and save the setup. You will be saving an usual xrandr command, which can be used in your script.
Here is my script.
It is very basic and actually only checks if a monitor of my desk is active. If so, it initialises the monitors of my desk. If not, it initialises my tv. It also sets the audio output I use with those monitors.
To get a list of all active monitors use this command:
xrandr --listactivemonitors | awk '!/Monitors/ {print $4}'
To get a list off all sinks(audio output) use this command:
pacmd list-sinks | grep -e 'name:' -e 'index:' | awk '{print $2}'| awk '{print substr($0, 2, length($0) - 2)}'
Now you can change my commands (sink and monitor names) with the onces you need. You can execute the script in the terminal so get feedback of the choosen sink and monitor (for testing). Don't forget to make your script executable else it won't work.
I got a similar script to manually change between my tv and my desk (mirroring scrrens, duplicate, tv-only, ect)
It too changes the sink according to the selected monitors. As you are using polybar too, you might notice that I relaunch polybar with sh /home/lluks/.config/polybar/launch.sh This is the script.
It ensures that my applets are displayed on the main monitor as poylbar can only display them on one monitor. This is archieved by using a 2 diffrent bars for poylbar.
For this script to work, you need dmenu and rofi. If I remember corretely, you also need Font Awesome for the icons.

Display big numbers in terminal

tmux can display big time like the picture below,
is there any way to display big numbers like that,
for example I want to show number of users in real time.
To the extent of my knowledge, there is no such feature in tmux. You could use watch (part of the procps tools) and figlet to implement such a feature:
watch runs a command periodically and prints the output on the screen. It always clears the screen before running the command.
figlet renders a string in a ASCII-Art style font. There a several fonts availiable.
So for instance you could show the number of users on a system (at least on Linux) using the following command line:
watch "who | wc -l | figlet -f big"
Unfortunatly the text won't be centered, as it is with clock-mode.

GUI wrapper for cygwin scripts?

I use some minor scripts at work under cygwin, and I would like to make them available to workmates with a familiar Windows icon. For instance, suppose I have the following:
cat *tsv | sort > combined_n_sorted.txt
Is there a simple way to make a corresponding icon, assuming cygwin is installed in my workmates' systems? These scripts may involve (cygwin's) python.
Thanks!
It seems that your question has two parts:
How to make scripts accessible on users' desktops.
How to give the each script a particular icon.
For (1), you could create a shortcut on the users' desktops that runs the following command:
C:\cygwin\bin\bash.exe -c 'cat *tsv | sort > combined_n_sorted.txt'
or if the commands are stored in a script,
C:\cygwin\bin\bash.exe -c /path/to/script
If you want to hide the console window from appearing while the script runs, you could use the run command (in the run package), e.g.:
C:\cygwin\bin\run.exe /bin/bash -c 'cat *tsv | sort > combined_n_sorted.txt'
# or
C:\cygwin\bin\run.exe /path/to/script
But it might be better for users to see the console window, so they know the script is running.
For (2), you can change each shortcut's icon individually by right-clicking on it and choosing Properties, but AFAIK that's a one-host-at-a-time change. I don't know of any batch way to do it, although no doubt there's a registry key you can set. Or, if you change the icon of the shortcut on your host and then distribute that shortcut, it might keep the same icon on other users' desktops, if the icon is a standard one that exists on their hosts.

Chrome on Linux - query the browser to see what tabs are open?

I am running Chromium (the open source chrome version) on Ubuntu Linux. Can I write a programme to see what tabs I have open? I would like to write a programme to monitor how much time I'm spending on things. Is there a command line programme, some way to invoke the chromium-browser command, or some dbus incantation that will tell me what tabs I have open and what URL each tab is at?
Chrome on Linux - query the browser to see what tabs are open?
For chromium :
strings ~/'.config/chromium/Default/Current Session' | 'grep' -E '^https?://'
Indeed there is a command line option which can open the door to a running chrome (chromium) process --remote-shell-port. Through this "debugging back-door" you may be able the get the list of open tabs.
Look at chromedevtools for further inspiration.
UPDATE:
Chrome DevTools is deprecated and not supported anymore since Version >17.0.950.*
See WebKit-Protocol manual if the new Debug-Framework provides similar manners to accomplish the task.
Here is a more general solution (works with other applications as well) by querying the X window under focus using xdotool
while true; do
xdotool getwindowfocus getwindowname;
sleep 10;
done
This outputs the following for instance:
Tilix: Defaultpeter-ThinkPad-T5801: peter#peter-ThinkPad-T580: ~
Chrome on Linux - query the browser to see what tabs are open? - Stack Overflow - Google Chrome
Local KVM
untitled — Atom
untitled — Atom
Open File
iostat_xtmz_3.out — ~/Work/KappAhl/Test1 — Atom
Tilix: Defaultpeter-ThinkPad-T5801: peter#peter-ThinkPad-T580: ~*
An expansion on the unix command above (I don't have enough reputation to comment). I was trying to just get a count of tabs. This still isn't perfect because I think the file has the entire history of all tabs in it. I guess they are in order, but not obvious how to separate them.
strings ~/Library/Application\ Support/Google/Chrome/Default/Sessions/Tabs_* | sed -nE 's/^([^:]+):\/\/(.*)\/$/\2/p' | grep -v "newtab" | grep -v "new-tab-page" | sort | uniq | wc -l
This is on mac, so your paths and sed options may vary.
The basic idea is to get rid of trailing slashes (lots of redirects just add a slash) and newtabs so we can get an accurate count. For my current tabs file this went from 181 tabs open down to a count of 35. That actually looks like an undercount right now, but it is a lot closer.
I have written a tool to extract data from chrome session files for precisely this purpose. https://github.com/lemnos/chrome-session-dump. Running it like so chrome-session-dump will produce a list of tabs (in order) which can subsequently be passed to firefox. E.G chrome-session-dump|xargs firefox. You can also obtain the currently open tab via -active for processing by external scripts.

Linux(Ubuntu) Terminal-how to view previous pages not visible anymore

When you scroll up, say to see a log, the first portion of it will not be visible since the terminal only supports a limited no. of lines. So if you want to scroll up and be able to see everything, at least a few pages up, how do you do it?
Use Shift+Page Up and Shift+Page Down.
Piping the output to a pager like the following is a better choice:
command | less
command | more
You can enable unlimited scroll back (or a huge amount if you want).
To do this, go to
File → Profile preferences → Scrolling [tab]
Then, check Unlimited, or set the number of lines desired. And of course, it only applies to the next typed lines.
Some tricks I use-
some terminal applications (gnome-terminal) allow you to increase the scroll-back buffer size
pipe output to a file:
command > file.log
pipe your command to less:
command | less
tail log and pipe to grep to reduce output
tail -f example.log | grep 'search text'
An alternative to screen is using tee to copy all output to a file while still printing it on the terminal:
yourcommand | tee output.txt
Try using the screen command, and set its scrollback buffer to a larger size.
screen has many other benefits and wonderful features.
If all you're doing is looking at a log, you could alternately use a pager such as less
If you want to scroll line by line, you can use
Control+Shift+Up/Down Arrows.
If you are using gnome-term (the default), then you can change your settings. Either set the no. of lines to unlimited, or to a much larger buffer size than the default.
Essentially seconding to #zerick's solution but if you're on gnome-terminal you can modify its config. See this.
If you are in tmux (can create multiple terminal sessions in a single terminal session, highly recommended), you can easily use your normal navigation keys to scroll around after you do Ctrl-b then [, for more details let's take a look at: How do I scroll in tmux?
None of these answer the original question. All answers are how to make new terminal windows (or current one) start behaving a certain way. The question is about how to see whats already scrolled away.
To answer this, each terminal session should have it's own "history" file (not to be confused with what command history is) containing all the stuff that relates to stdin/stdout displayed. I could be wrong but this may be different depending on the terminal emulator you use. Some just trash it when you close the window/ end the session.
I am trying to get this figured out myself so here is the more direct answer in a different thread.
https://unix.stackexchange.com/questions/145050/what-exactly-is-scrollback-and-scrollback-buffer
From what this tells me, I suspect best advice you can get is, for whatever terminal emulator you use, look for where it stores the scrollback buffer and that might be your only hope. It's what I am going to try right now. (and that is IF the session is currently still open, not closed terminal windows)

Resources