You are not logged in.
Hi,
I add some keybinds to place my window with super + h or super + l to the left or right half of my screen.
On my mac, i use "rectangle" to place my windows the same way, but this app have a cool feature :
If my window is already half of the screen, and i press super + l again, it will have 75% size, if i repeat super + l again, it will have 25% size. (i think it's called "cycling", sorry that's hard to explain in english)
So, i tried to find a way to add some condition in the bl-rc.xml (something like "if width=50% then width=75%") without success.
Do you think i can do this directly in the bl-rc.xml ?
Offline
Yes, you can add some new keybindings.
Openbox has excellent fine-grained control of the window.
Take a look at the window actions:
http://openbox.org/wiki/Help:Actions
You may be able to use the "if" action to get mac-like key binds.
You must unlearn what you have learned.
-- yoda
Offline
Thanks,
Ok, so i should find the right syntax, because i can't find how to conditionally change the windows size.
Since i'm not sure my message is really understandable, here is gif of what i try to have on openbox by repeating "super + L" :
Edit :
Not working, should i use the Stop action after the first condition ?
```
<keybind key="W-l">
<action name="Unmaximize"/>
<action name="If">
<query>
<width>50%</width>
<height>100%</height>
<x>-0</x>
<y>0</y>
</query>
<then>
<action name="MoveResizeTo">
<width>75%</width>
<height>100%</height>
<x>-0</x>
<y>0</y>
</action>
</then>
<else>
<action name="MoveResizeTo">
<width>50%</width>
<height>100%</height>
<x>-0</x>
<y>0</y>
</action>
</else>
</action>
</keybind>
```
Last edited by GllmR (2023-04-23 17:36:53)
Offline
I don't think you got syntax even close, see
http://openbox.org/wiki/Help:Actions#If
and I don't think this will work at all in your case (it doesn't look like the conditions can be that specific).
The solution could be the external script that evaluates/modifies the selected window - mapped to some key. There are utilities like wmctrl, xdotool and xprop.
An example: https://github.com/brontosaurusrex/buce … n/drawTerm
that will open urxvt at the size that you just draw with the mouse.
I could be wrong.
Last edited by brontosaurusrex (2023-04-23 18:29:39)
Offline
This is the first time I play with XML
It seemed too easy, the "if" example looked much less specific.
I'll have a look at the software you suggest, thanks.
Offline
Ok, it works more or less... wtcrl doesn't take window decorations into account. And I still don't know how I'm going to detect when the window is at 50%, but it's a start.
```
string=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
window_id=$(echo "$string" | cut -d ' ' -f 5)
screen_width=$(xdpyinfo | awk '/dimensions/{print $2}' | cut -d 'x' -f 1)
screen_height=$(xdpyinfo | awk '/dimensions/{print $2}' | cut -d 'x' -f 2)
window_height=$(echo "$screen_height" | bc | cut -d '.' -f 1)
half_window=$(echo "$screen_width * 0.5" | bc | cut -d '.' -f 1)
wmctrl -i -r "$window_id" -e 0,0,0,"$half_window","$window_height"
```
Edit: Just noticed i could use wmctrl -r :ACTIVE: haha
Last edited by GllmR (2023-04-24 20:37:36)
Offline
You are getting there it seems. Another option may be heavily configured and possibly changed rtile (ruby)
https://github.com/xhsdf/rtile
again not sure.
Offline
After some ChatGPT and some correction, i got what i want.
#!/bin/bash
# define the height in px of the top system-bar:
TOPMARGIN=30
# calculate new width and height with 5 pixel margin
MARGIN=5
# get width of screen and height of screen
SCREEN_WIDTH=$(xwininfo -root | awk '$1=="Width:" {print $2}')
SCREEN_HEIGHT=$(xwininfo -root | awk '$1=="Height:" {print $2}')
# get active window width and position
WINDOW_WIDTH=$(xwininfo -id "$(xprop -root _NET_ACTIVE_WINDOW | awk '{print $5}')" | grep "Width" | awk '{print $2}')
WINDOW_X=$(xwininfo -id "$(xprop -root _NET_ACTIVE_WINDOW | awk '{print $5}')" | grep "Absolute upper-left X" | awk '{print $4}')
if [ $WINDOW_WIDTH -eq $((SCREEN_WIDTH/2-MARGIN*2)) ] && [ $WINDOW_X -eq $((SCREEN_WIDTH/2+MARGIN)) ]; then
NEW_WIDTH=$((SCREEN_WIDTH*2/3 -MARGIN*2))
NEW_X=$((SCREEN_WIDTH/3+MARGIN))
elif [ $WINDOW_WIDTH -eq $((SCREEN_WIDTH*2/3-MARGIN*2)) ] && [ $WINDOW_X -eq $((SCREEN_WIDTH/3+MARGIN)) ]; then
NEW_WIDTH=$((SCREEN_WIDTH/3-MARGIN*2))
NEW_X=$((SCREEN_WIDTH*2/3+MARGIN))
else
NEW_WIDTH=$((SCREEN_WIDTH/2-MARGIN*2))
NEW_X=$((SCREEN_WIDTH/2+MARGIN))
fi
# calculate new height and position with 5 pixel margin
NEW_HEIGHT=$((SCREEN_HEIGHT-2*TOPMARGIN-MARGIN*2))
NEW_Y=$((TOPMARGIN+MARGIN))
# resize and move window
wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,$NEW_X,$NEW_Y,$NEW_WIDTH,$NEW_HEIGHT
Last edited by GllmR (2023-04-30 20:07:41)
Offline
Unfortunately, this script doesn't work with some softwares: Firefox goes under my "conky" bar and thunar takes a strange height.
The script works perfectly with kitty or vlc.
Can someone tell me why?
Offline