Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GtkButton instead of GtkLabel for Modules #1120

Merged
merged 4 commits into from
Oct 17, 2022

Conversation

pinselimo
Copy link
Contributor

This PR turns the GtkLabel into a GtkButton. This has some visual advantages:

  • The :hover qualifier can be set on modules in style.css
  • There is a nice hover and click animation of the label included
  • If the module is merely informative, the button is deactivated and acts just as before

Checkout my dotfiles (.config/waybar/*) for how I use this PR to distinguish modules spawning a window on click from those just changing format.

Caveats: GtkButton catches all single mouse button click events regardless of the flags set on it. Therefore, I had to connect its signal_pressed method to the underlying, preceding handleToggle method.
Another workaround would have been to connect handelToggle to signal_button_release_event instead of signal_button_press_event in AModule. I've done that in my 'use_gtk_button' (without the '_v2') branch. The implementation of '_v2' mimics the previous behavior much better though.

Thanks :)

The AButton class is designed as full a substitute to ALabel. The
GtkButton attribute 'button_' is initialized with a label. This
label can the be referenced by the subsequent inheritors of AButton
instead of the GtkLabel attribute 'label_' of ALabel.
For convenience a GtkLabel* 'label_' attribute is added to AButton.

If the button cannot be clicked it is disabled, effectively acting
like its label predecessor.

GtkButton seems to catch one-click mouse events regardless of the
flags set on it. Therefore, 'signal_pressed' is connected to a
function creating a fake GdkEventButton* and calling 'handleToggle'
(for details on this possible bug in GTK see:
https://stackoverflow.com/questions/45334911 )

In accordance with other GtkButtons (i.e. the sway/workspace ones)
set_relief(Gtk::RELIEF_NONE) is called on the 'button_' instance.
Since now modules as well as workspaces are buttons, the fix for
the 'strange hover effects' has to be applied on a global level.
In return there is a nice hover effect also on the modules.
Fixes issue where the class parameters in style.css would have no
effect.

The CSS now references the GtkButton instead of the GtkLabel. Removing
all style-classes from the custom module GtkButton however removes
any properties set via style.css. Thus, the default classes 'flat' and
'text-button' are added on every update of these modules.
Mouse-over tooltips set on the label only appear once the mouse hovers
over exactly the label. Other apps (e.g. firefox) show the tooltip once
the pointer hovers the button. Not solely its label. With this commit we
get the same behaviour.
@Alexays Alexays merged commit bfa3adc into Alexays:master Oct 17, 2022
@pinselimo pinselimo deleted the use_gtk_button_v2 branch October 17, 2022 08:43
@lilydjwg
Copy link
Contributor

lilydjwg commented Oct 18, 2022

Hi, how can I customize the hover background? I don't want my widgets which are on a black bar to turn their background to white on hovering. I tried several kinds of :hover rules but didn't find the right one to use.

Affected widgets are: two customs (not all of them), idle inhibitor and pulseaudio.

@Alexays
Copy link
Owner

Alexays commented Oct 18, 2022

@pinselimo Can you check this issue #1726
And add change to default style.css in order to keep background unchanged on hover?

@pinselimo
Copy link
Contributor Author

@lilydjwg you can change the color using border-color.

Interestingly, the halo-effect disappears if the border attribute for buttons is set, no matter which value.

@Alexays should there be no hover effects at all, or an effect similar to the workspace buttons where the bottom lights up?

@Alexays
Copy link
Owner

Alexays commented Oct 18, 2022

@pinselimo we can have a hover effect only if in the default config, the module have a click event, otherwise we'll let the user change that according to his needs.

@lilydjwg
Copy link
Contributor

@pinselimo we may have been talking about different issues. The issue I have is this:

图片

The purple text is my custom widget to show the focused window title. This widget and the bar has a black background. When I hover on the widget, it has a white background like the screenshot, and I failed to make it black (i.e. I don't want it to change on hovering).

My style.css.

@pinselimo
Copy link
Contributor Author

Ah I see, then just add:

button:hover {
    background: rgba(0, 0, 0, 0.2);
    box-shadow: inherit;
}

from the default style.css to yours. Fixes the issue for me. If you want to keep the hover effect on the workspace buttons, where it should have been before(?) also add:

#workspaces button:hover {
    background: #ffffff;
}

lilydjwg added a commit to lilydjwg/dotconfig that referenced this pull request Oct 18, 2022
@lilydjwg
Copy link
Contributor

@pinselimo thanks, it works! Actually I don't use the workspace widget because I'm using wayfire....

@danielrparks danielrparks mentioned this pull request Oct 20, 2022
cosandr added a commit to cosandr/dotfiles that referenced this pull request Oct 22, 2022
Set a default color, issue seems to have been introduced by Alexays/Waybar#1120
@djvs
Copy link

djvs commented Mar 29, 2023

If anyone is looking to retain buttons until Gtk4 migration is done or whatever, use commit ce8ae5bf17c11c441d8365acdb39625d32b6c2a2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants