I want to change top panel color and alpha when any window is maximized.
For now I have something like this:
#!/bin/bash
while [ 1 = 1 ]
do
if window_is_maximized
then
xfconf-query -c xfce4-panel -p /panels/panel-0/background-alpha -s 100
else
xfconf-query -c xfce4-panel -p /panels/panel-0/background-alpha -s 50
fi
done
Maximized windows in X do not have a special state that you can test reliably. From a script, you can use xwininfo:
You can check if the window happens to be the same size as the root (main) window, and its position is the upper-left corner.
If you happen to be using a window manager which supports certain EMWH properties (_NET_WM_STATE_FULLSCREEN, _NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_MAXIMIZED_HORZ), your script could check for those. But in a quick check for window managers which might do that, I found none.
Related
I have these lines in my i3 configuration file:
# Startup applications.
exec firefox
exec gnome-terminal
exec nautilus
These lines start firefox, gnome-terminal and nautilus as expected, but the order in which they start is unpredictable. Is there a way to start these applications in a way that makes the windows appear in the order that I want? (i.e. firefox, then gnome-terminal, then nautilus).
Refer to Layout saving in i3.
Add this to the i3 configuration file:
# Create specific layout for applications.
exec --no-startup-id "i3-msg 'workspace 1; append_layout ~/.config/i3/workspace-1.json'"
# Start applications.
exec firefox
exec gnome-terminal
Create ~/.config/i3/workspace-1.json:
// Layout of a workspace.
{
"layout": "tabbed",
// To get a window's class name, run xprop and click on the window.
// You will see the following output:
// WM_CLASS(STRING) = "InstanceName", "ClassName"
// Alternatively, "swallow" by the window's title.
"nodes": [
{"swallows": [{"class": "^Firefox$"}]},
{"swallows": [{"class": "^Gnome-terminal$"}]}
]
}
You can save layouts so that each application is captured by a predefined window container. Making it truly automatic requires a little extra scripting. Examples from my configuration:
i3 config
assign [class="^Vivaldi-stable$"] 1
assign [class="^Keepassx2$"] 2
assign [class="^Thunderbird$"] 2
....
# last line
exec ~/.config/i3/restore.sh &
restore.sh
#!/bin/sh
for layout in ~/.config/i3/layouts/*; do
i3-msg "workspace $(basename "$layout" .json); append_layout $layout"
done
(vivaldi-stable &)
(keepassxc &)
(thunderbird &)
If you want to see the full version, my dotfiles are on GitHub.
I often run Vim in a tmux session to I can run tests in an adjacent pane. On a smaller monitor, I either have to sacrifice more Vim screen real estate than I'd like, or make the test pane too small to read the full results (which is fine if everything passes, but not when there are failures and I need to see the details).
Then my workflow becomes:
trigger tests from within Vim
switch to test pane (last-pane)
zoom pane to occupy full window (resize-pane -Z)
read the results
restore original layout (resize-pane -Z)
switch back to Vim pane (last-pane)
I wanted to add a key binding that I could use when I'm in the Vim pane to zoom the test pane (hiding Vim), and be able to use the same binding once zoomed to restore the original layout, returning me to Vim. This is what I came up with, but I wonder if there's a better way I can do it. I had to set, check, and unset an environment variable to save the state that would support toggling back and forth with the same key binding. I also haven't figured out how to make the toggle state specific to a window (right now, any multi-window session shares the state across all its windows, so this doesn't work correctly)
bind Space if-shell '[ -z "${ALT_PANE_ZOOM+x}" ]' \
'select-pane -t :.+; resize-pane -Z; set-environment ALT_PANE_ZOOM 1' \
'set-environment -u ALT_PANE_ZOOM; last-pane'
Update:
I found a simpler solution. Rather than relying on a per-window environment variable, I can leverage -F and the window_zoomed_flag format variable:
bind Space if-shell -F '#{window_zoomed_flag}' \
'last-pane' \
'select-pane -t :.+; resize-pane -Z'
In your tmux.conf, create a keybind which:
Saves the zoom state
Switch to the last pane, unzooming if a pane was zoomed in
Conditionally zooms depending on the zoomed state in #1
-
bind key run-shell "tmux setenv zoomed $(tmux display -p '#{window_zoomed_flag}')"\; \
last-pane\; \
run-shell "test $(tmux display -p '#{zoomed}') -ne 0 || tmux resize-pane -Z"
Note that the backslash escapes on the semicolons command separators are required.
I am trying to figure out how to not lose focus in a shell script while simultaneously displaying an image. User input may come at any time, but seeing the photo taken, would seem important.
To Clarify, I have no problem outputing an image. display works fine, as does animate, and feh, etc.. what i need is for the shellscript to still process user input, (in this example, "t") while displaying the last image taken, for an undefined amount of time.
I'm writing in bash, in Linux.
Heres an example of what I'm trying:
#!/bin/bash
i=0
capture() {
cd ~/Desktop/ani
streamer -c /dev/video0 -s 800x600 -o outfile$i.jpeg
display outfile$i.jpeg &
let i++
}
while true; do
#clear
read -rsn1 input
if [ "$input" = "t" ]; then
capture
else
exit
fi
done
In the actual script I may continue to take photos, so I want to continue listening for user input. I can imagine a couple ways to do this, but I cannot figure it out.
To continue listening user input. you can do like
while true; do
#clear
read -p "Your input: " input
if [ "$input" == "t" ]; then
capture
fi
done
A rather ugly way to solve this: install the utility wmctrl (in debian/Ubuntu, sudo apt-get install wmctrl). Then, after your display command, add:
sleep 1
wmctrl -i -a "$WINDOWID"
This will sleep for one second (to leave some time to the display command to finish loading—tune this value to whatever feels right to you). Then, wmctrl will use the value of the variable WINDOWID (that is hopefully set by your terminal emulator) as a numeric value (-i) and raise the window and give it focus (-a).
Is there a way to list all window names and depending on the result, creating a new window with a specific name into this (running) session.
How to create a new screen session with assigned window names is documented in the man pages, but i could find information about a solution to the problem above.
From outside the screen session, I don't think so.
But if you are starting from inside, in one of the windows of the right screen session, then yes:
for window_name in foo bar baz quux ; do ## ...
screen -t $window_name
done
You can even get fancy and run some initial commands in each window! This snipped of copy-paste bash helps me get back to work quickly after a reboot. Once I've started the screen session:
for n in $(seq 1 8) ; do ## ...
screen -t proj_$n bash -c "cd /src/foo/proj_$n*/ ;"\
' eval `set_proj_env_vars.sh` ; svn status ; make clean ; make ;'\
' exec bash --login'
done
...and as a great side effect the screen windows are numbered for the various checkouts, where each one can be working on a different bug/feature. Overkill? Totally! But it's a fun hack.
I'm looking for a way to display the active user for each window in a GNU screen session in its the hardstatus line.
Example
I have the following windows open
Window 0 - user1#localmachine
Window 1 - user1#localmachine
Window 2 - user1#localmachine SSH to user2#remotemachine
At the moment the hardstatus is:
0$ something [user1] 1$ something [user1] 2$ something [user2]
Where something [username] is typed in manually.
Is there any way to automatically display the windows current user?
You can use an escape sequence to set the window title, if that's what you want:
echo -e '\033k'$USER#$HOSTNAME'\033\\'
Just add this line to your .bashrc or similar file.