swaywm / sway

i3-compatible Wayland compositor
https://swaywm.org
MIT License
14.77k stars 1.11k forks source link

swaybar: Left/right anchoring support. #3373

Open cedws opened 5 years ago

cedws commented 5 years ago

I've seen a few mentions of vertical swaybar support in past issues. Currently, i3bar doesn't support left/right anchoring, but there is an issue open for it.

I can have a go at implementing this depending on whether people are open to the idea. I'll probably need to do it in stages and clarify how certain aspects will behave, such as whether text will display vertically, or render horizontally and expand the bar width.

mstoeckl commented 5 years ago

0001-proof-of-concept-for-rotating-swaybar.patch.txt

TLDR: Adding left/right bar anchor options is easy. It's straightforward to render swaybar rotated 90 degrees CCW, thanks to cairo_transform; the main coordinate wrangling that needs to be done is to replace width and height (in the screen frame) with length and breadth (in the transformed frame).

The patch implements the bare minimum. Fixing hotspots/mouse interaction requires a bit of additional logic, while optionally counterrotating text to be horizontal probably requires a lot more work.

Sadly, I don't have the time to bring this patch to completion, but it may form a good starting point.

RyanDwyer commented 5 years ago

I think for this to be practical the text must not be rotated. And as mentioned, that introduces challenges like choosing the width of the bar and figuring out how to lay out the elements (tray icons especially).

I think this would be better suited to a third party program. Swaybar is text based, and text doesn't work very well for vertical bars due to it needing to be truncated. An icon-based bar would work better. And implementing this in swaybar would mean adding more configuration directives and code paths to support, with these only being used by a small fraction of users.

cedws commented 5 years ago

Custom workspace names could be disabled when the bar is vertical so that only single digit numbers are displayed, but I don't think that's a good solution. Any thoughts @ddevault?

ddevault commented 5 years ago

Some languages lend themselves well to being written vertically, notably CJK languages. I would be interested in seeing a patch for a veritcal bar, both with CJK support and with a bar as wide as its contents (or with a user-defined minimum, ala the height parameter already supported by sway).

kennylevinsen commented 5 years ago

I would expect a vertical bar to either have rotated text or vertical writing, with the former being both easier and more aesthetically pleasing (with the exception being natively vertical scripts, as those @ddevault refers to).

My use-case is simple that a vertical bar wastes less space. With horizontal text and dynamic width bar, that would no longer be the case, as even just the current time would make the bar very, very wide to accommodate its content.

This is definitely a nice-to-have, but if the rotation transform and input handling isn't a lot of code (the patch from @mstoeckl definitely seems minimal, although it lacks the input part), I'd definitely vote for the enhancement with text simply rotating with the bar. Although, in that case, it might be nice to be able to pick which way it rotates separate from which side it attaches to. That setting could then maybe also be used for future support of counter-rotated text (vertical script or not).

kennylevinsen commented 5 years ago

This patch takes the work from @mstoeckl, and expands it to remap input correctly.

vertical-swaybar.patch.txt

However, it still lacks the ability to control the rotation. Right now, anchoring left/right results in a fixed 90 degree anticlockwise rotation. Maybe a separate "flip" parameter to control that?

EDIT: Attach the patch. :|

EDIT2: After far too long, I realized that the original patch from @mstoeckl was actually bottom-to-top, which while potentially what some people might want, definitely does not work out well as a sensible default.

The following patch inverts this to top-to-bottom: vertical-swaybar-top-to-bottom.patch.txt

EDIT3: Patches available in the fork https://github.com/kennylevinsen/sway as "dev/kl-vertical-swaybar" and "dev/kl-vertical-swaybar-counterrotated". Also includes a tray-icon size fix.

cedws commented 5 years ago

These patches are great @kennylevinsen. I checked out your kl-vertical-swaybar-counterrotated branch. The position of text on the bar seems to be slightly off.

image

I have to say, it will be a struggle to read any meaningful info from the bar like this. That's alright though, there's other ways of looking at the date etc.

kennylevinsen commented 5 years ago

Yeah, I have noticed two issues with the counter-rotated text:

  1. Wide characters do not increase status bar width and are rendered as if two characters were present. Not entirely sure what to do here—pango seems confused.
  2. Text seems to have weird alignment. Pango is reponsible for positioning the characters, so I'm not entirely sure why a single string of text dances around so much. It also seems to be slightly system dependent, as I at least get perfectly centered workspace buttons.

I don't like the counter-rotated version myself for latin scripts, but I'm not one to judge. However, if we don't want the feature for latin scripts, it should be possible to make pango either write latin scripts as rotated horizontal text, while vertical scripts are automatically counter-rotated. This would be done by removing the "strong" hint applied to the pango functions.

I'm quite satisfied with the non-counter-rotated version, though. Saves space, not too hard to read, and seems to work.

kennylevinsen commented 5 years ago

Hmm, I just checked with some Chinese, and the wide character issue might just be a font-awesome problem (I observed it with font-awesome icons). Chinese writing at least renders at a correctly when vertical.

I also added a branch (dev/kl-vertical-swaybar-counterrotate-cjk-only) where only vertical scripts are counter-rotated (as per pangos understanding of what scripts are natively vertical). This means for example that Chinese text will correctly render vertically, where latin scripts will simply render rotated.

If I get time, I'll try to set up a cairo/pango test application to debug the jumpy alignment of counter-rotated latin, just to see if I can get it fixed, just in case we also want to be able to force vertical rendering of latin text.

matthiasbeyer commented 5 years ago

I just found that waybar supports left/right bars, but sway does not allocate screen space for the bar like it does for top/bottom bar.

Shall I open a new issue for that or does it belong here?

emersion commented 5 years ago

This is likely a waybar issue.

matthiasbeyer commented 5 years ago

How's that? I can see that when starting waybar (in a terminal) in sway, that sway shrinks the windows on the screen so that waybar fits in and does not get covered (or hides) the windows on the screen... so I assumed that this is a sway issue rather than a waybar issue.

Care to explain?

emersion commented 5 years ago

Waybar needs to ask for an exclusive region. They probably don't.

systo commented 5 years ago

Would there be an option of having a 4-5 character wide bar as an option?

1 | 2 
3 | 4 

DD-MM
YYYY
devosalain commented 3 years ago

In waybar config i have put, "position","left". But it does not work. The bar remains at the top ...

emersion commented 3 years ago

This issue is about swaybar, not waybar.

devosalain commented 3 years ago

My bad, i mixed both. But is there something I can try in my /home/myuser/.config/sway/config file.