labwc / labwc

A Wayland window-stacking compositor

Home Page:https://labwc.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[feature request] "Center" action for WindowRules

01micko opened this issue · comments

commented

I am making some little dialogs wit Yad and the --center doesn't work in labwc and the developer hasn't much interest in supporting wayland.

Here's my work-around (on second output)-

  <windowRules>
      <windowRule identifier="dialog-*" matchOnce="false">
        <action name="MoveTo" x="2680" y="490" />
        <action name="ResizeTo" width="400" height="100"/>
      </windowRule>
    </windowRules>

<action name="Center" /> would be nice.

Works ok, but I don't want to bother working out screen res and sed'ing in correct values for other monitors, they call it 'lazy' I think.

Yad has other bugs but I get around them in other ways - like no taskbar icon shows with --window-con so I use --name which coincedentally adds it as [xdg-shell] in the window switcher, but I digress.

Thanks for consideration.

need-center-rule

commented

So I got unlazy..

#!/usr/bin/env bash

read dims discard <<<$(wlr-randr | grep current)
x=${dims%x*}
y=${dims#*x}
appdlg=(400 100)
appprf=(550 375)
halfx=$((x / 2))
halfy=$((y / 2))
hfappgw=$((appdlg[0] / 2))
hfappgh=$((appdlg[1] / 2))
hfapppw=$((appprf[0] / 2))
hfappph=$((appprf[1] / 2))

dlgxpos=$((halfx - hfappgw))
dlgypos=$((halfy - hfappgh))
prfxpos=$((halfx - hfapppw))
prfypos=$((halfy - hfappph))

ndlg=$(grep -n 'dialog-*' $HOME/.config/labwc/rc.xml)
nd=${ndlg%\:*}
ndpos=$((nd + 1))
ndsiz=$((nd + 2))
nprf=$(grep -n 'preferences-*' $HOME/.config/labwc/rc.xml)
np=${nprf%\:*}
nppos=$((np + 1))
npsiz=$((np + 2))
sed -i -e "${ndpos}s/x.*/x=\"$dlgxpos\" y=\"$dlgypos\"\/>/" \
       -e "${ndsiz}s/width.*/width=\"${appdlg[0]}\" height=\"${appdlg[1]}\"\/>/" \
       -e "${nppos}s/x.*/x=\"$prfxpos\" y=\"$prfypos\"\/>/" \
       -e "${npsiz}s/width.*/width=\"${appprf[0]}\" height=\"${appprf[1]}\"\/>/" \
        $HOME/.config/labwc/rc.xml

With 1920x1080 res here's the result:

  <windowRules>
    <windowRule identifier="dialog-*" matchOnce="false">
      <action name="MoveTo" x="760" y="490"/>
      <action name="ResizeTo" width="400" height="100"/>
    </windowRule>
    <windowRule identifier="preferences-*" matchOnce="false">
      <action name="MoveTo" x="685" y="353"/>
      <action name="ResizeTo" width="550" height="375"/>
    </windowRule>
  </windowRules>

Still would like the feature; took a look but a bit beyond my capability.

There's a placement policy of center so it might not be that hard to hook into that as a separate action.

The right approach here is modifying the AutoPlace action to accept an argument like policy="[center|cursor|automatic]", defaulting to automatic for backward compatibility, and modifying the action handler to invoke the right view-moving routine.

commented

Thanks @ahesford works perfectly :)

  <windowRules>
    <windowRule identifier="dialog-*" matchOnce="false">
      <action name="AutoPlace" policy="center"/>*
    </windowRule>
    <windowRule identifier="preferences-*" matchOnce="false">
      <action name="AutoPlace" policy="center"/>*
    </windowRule>
  </windowRules>
center-policy.mp4

Actually a duplicate of #1511, so closing 2 issues :)

commented

Actually a duplicate of #1511, so closing 2 issues :)

Oh, sorry! I did browse through issues and must have missed it.