How to activate GtkNotebook page on middle click? (original) (raw)
September 17, 2024, 9:02am 1
I found this widget works with GDK_BUTTON_PRIMARY
only
How to make page activation on click GDK_BUTTON_MIDDLE
too?
Thanks
d47081 (D47081) September 17, 2024, 12:05pm 2
Found how to assign all buttons by create new event controller, but still don’t understand how to activate the Notebook tab on click
// GtkNotebook Label widget
const auto controller = Gtk::GestureClick::create();
controller->set_button(
0 // all
);
add_controller(
controller
);
controller->signal_pressed().connect(
[this](int n, double x, double y)
{
activate(); // not works
}
);
upd. seems the answer is here:
thanks to
upd2.
this *code still does not work, lol
// Gtk::Notebook
const auto controller = Gtk::GestureClick::create();
controller->set_button(
GDK_BUTTON_MIDDLE
);
add_controller(
controller
);
controller->signal_pressed().connect(
[this](int n, double x, double y)
{
auto widget = pick(x, y);
if (NULL != widget)
{
auto i = page_num(*widget);
if (i >= 0) // -1, fails as not found
{
set_current_page(i);
}
}
}
);
gwillems September 27, 2024, 3:52pm 4
Shouldn’t it beauto i = page_num(widget);
?
gwillems September 27, 2024, 4:10pm 5
Also, don’t mix the tab widget with the page widget:
Should look like this:
tab_widget = pick(x, y);
for page in gtk_notebook_get_pages ()
if page.tab == tab_widget
i = page_num(page.child);
set_current_page(i);
d47081 (D47081) October 8, 2024, 5:23am 6
Thanks for advice, after some pause returned to this question, let me try again…
By the way, interesting, is it possible to assign few buttons to one GestureClick
, not create 2 separated controllers for primary and middle click?
ebassi (Emmanuele Bassi) October 8, 2024, 9:48am 7
No: you’re supposed to create a different event controller, since you’re likely going to have two different behaviours.
d47081 (D47081) October 8, 2024, 4:18pm 8
Thanks,
but what about close (or activate) tab on middle click?
I wonder pick(x, y)
is only one possible solution, but it’s super tricky, can’t believe there is no way to emit this signal to this Label, the parent GtkGizmo
, or assign one click controller to another one (if I can’t use few buttons for one GestureClick
)
Found this idea
but why so hard for simple task… thoughts make new action, assign it to the label widget and try to activate on middle click
d47081 (D47081) October 9, 2024, 2:30am 9
libadwaita
does everything I want
system (system) Closed November 8, 2024, 2:31am 10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.