glzr-io / zebar

Zebar is a tool for creating customizable and cross-platform taskbars, desktop widgets, and popups.
GNU General Public License v3.0
818 stars 43 forks source link

[Bug] Scaling bar height based on monitor scale factor #72

Closed pu-007 closed 4 weeks ago

pu-007 commented 2 months ago

image I possess two monitors. The initial one is my typical monitor, yet the second one is a larger monitor with a scale of 300%. When I activate Monitor 2 and switch to it while Zebar is operational, the bar fails to resize automatically and remains in a small size.

pu-007 commented 2 months ago
def MonitorHook(mode: str):
    # kill zebar.exe, and run C:\Users\Administrator\.glzr\zebar\start.bat
    from subprocess import call
    from screeninfo import get_monitors
    from ruamel.yaml import YAML

    yaml = YAML()
    yaml.preserve_quotes = True

    call(["taskkill", "/IM", "zebar.exe", "/F"])
    call([r"C:\Users\Administrator\.glzr\zebar\start.bat"])

    config = open(r"C:\Users\Administrator\.glzr\glazewm\config.yaml", "r")
    yaml_data = yaml.load(config)
    config.close()
    yaml_data["gaps"]["outer_gap"]["top"] = (
        "3%" if get_monitors()[0].width == 2560 else "4%"
    )
    config = open(r"C:\Users\Administrator\.glzr\glazewm\config.yaml", "w")
    yaml.dump(yaml_data, config)
    config.close()
    keyboard.redraw() # press (altleft + shift + r) by pyautogui.hotkey
window/bar:
  # Height of the window in physical pixels.
  height: "{{self.args.MONITOR_SCALE_FACTOR * 30}}"

I have composed a script to address the issue provisionally and am still anticipating a more optimal and inherent solution.

ivara commented 2 months ago

I "suffer" from this issue as well. My work setup is laptop + external monitor. The laptop runs 175% zoom and external monitor 100% and zebar gets "broken" on my laptop monitor

hongyuanjia commented 2 months ago

I also have this issue. My PC has two monitors. One is 4K with 200% zoom, and the other is 1080p with 100% zoom. I have trouble integrating Zebra with Glazewm's outer_gap options.

hongyuanjia commented 2 months ago

@pu-007 Using the scale factor for the height is brilliant. I wonder how you set the outer_gap for each monitor.

pu-007 commented 2 months ago

@pu-007 Using the scale factor for the height is brilliant. I wonder how you set the outer_gap for each monitor.

I am uncertain whether there exists a native API to obtain the scale factor with Glazewm. However, I have two alternative solutions for this issue.

The first solution is to set outer_gap.top to 4%, thereby enabling adaptation to various monitors. (It's not a perfect adaptation) The second one is writing a script, which can detect the monitor you are using and modify the outer_gap in YAML configuration to different scales and refresh it.

hongyuanjia commented 2 months ago

which can detect the monitor you are using and modify the outer_gap in YAML configuration to different scales and refresh it.

The outer_gap.top is a global value for all monitors, right? Will all monitors be affected when you change the value dynamically?

pu-007 commented 2 months ago

which can detect the monitor you are using and modify the outer_gap in YAML configuration to different scales and refresh it.

The outer_gap.top is a global value for all monitors, right? Will all monitors be affected when you change the value dynamically?

Yeah, that's right. It seems not to support separate configurations.

lars-berger commented 4 weeks ago

Fixed now in the latest v2.3.0 release 🙌