You are not logged in.

#1 2023-04-22 22:13:33

GllmR
Member
Registered: 2023-02-13
Posts: 13
Website

Openbox: Change window size by repeating a keybind

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

#2 2023-04-23 00:30:08

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,660

Re: Openbox: Change window size by repeating a keybind

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

Online

#3 2023-04-23 13:53:34

GllmR
Member
Registered: 2023-02-13
Posts: 13
Website

Re: Openbox: Change window size by repeating a keybind

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" :

GIF

https://imgur.com/a/rtXc3XA


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

#4 2023-04-23 18:25:25

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: Openbox: Change window size by repeating a keybind

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

#5 2023-04-24 07:48:01

GllmR
Member
Registered: 2023-02-13
Posts: 13
Website

Re: Openbox: Change window size by repeating a keybind

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

#6 2023-04-24 20:34:21

GllmR
Member
Registered: 2023-02-13
Posts: 13
Website

Re: Openbox: Change window size by repeating a keybind

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

#7 2023-04-25 09:16:17

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: Openbox: Change window size by repeating a keybind

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

#8 2023-04-30 17:11:05

GllmR
Member
Registered: 2023-02-13
Posts: 13
Website

Re: Openbox: Change window size by repeating a keybind

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

#9 2023-05-02 08:01:43

GllmR
Member
Registered: 2023-02-13
Posts: 13
Website

Re: Openbox: Change window size by repeating a keybind

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

Board footer

Powered by FluxBB