Skip to content

Commit 5d184f7

Browse files
authored
Merge pull request Alexays#3506 from soreau/taskbar-minimize-hints
taskbar: Send minimize geometry hints
2 parents f665d1d + 4d89c64 commit 5d184f7

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

include/modules/wlr/taskbar.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
namespace waybar::modules::wlr {
2626

27+
struct widget_geometry {
28+
int x, y, w, h;
29+
};
30+
2731
class Taskbar;
2832

2933
class Task {
@@ -42,6 +46,7 @@ class Task {
4246
};
4347
// made public so TaskBar can reorder based on configuration.
4448
Gtk::Button button;
49+
struct widget_geometry minimize_hint;
4550

4651
private:
4752
static uint32_t global_id;
@@ -82,6 +87,8 @@ class Task {
8287
private:
8388
std::string repr() const;
8489
std::string state_string(bool = false) const;
90+
void set_minimize_hint();
91+
void on_button_size_allocated(Gtk::Allocation &alloc);
8592
void set_app_info_from_app_id_list(const std::string &app_id_list);
8693
bool image_load_icon(Gtk::Image &image, const Glib::RefPtr<Gtk::IconTheme> &icon_theme,
8794
Glib::RefPtr<Gio::DesktopAppInfo> app_info, int size);

src/modules/wlr/taskbar.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ void Task::handle_title(const char *title) {
387387
hide_if_ignored();
388388
}
389389

390+
void Task::set_minimize_hint() {
391+
zwlr_foreign_toplevel_handle_v1_set_rectangle(handle_, bar_.surface, minimize_hint.x,
392+
minimize_hint.y, minimize_hint.w, minimize_hint.h);
393+
}
394+
390395
void Task::hide_if_ignored() {
391396
if (tbar_->ignore_list().count(app_id_) || tbar_->ignore_list().count(title_)) {
392397
ignored_ = true;
@@ -447,6 +452,13 @@ void Task::handle_app_id(const char *app_id) {
447452
spdlog::debug("Couldn't find icon for {}", app_id_);
448453
}
449454

455+
void Task::on_button_size_allocated(Gtk::Allocation &alloc) {
456+
gtk_widget_translate_coordinates(GTK_WIDGET(button.gobj()), GTK_WIDGET(bar_.window.gobj()), 0, 0,
457+
&minimize_hint.x, &minimize_hint.y);
458+
minimize_hint.w = button.get_width();
459+
minimize_hint.h = button.get_height();
460+
}
461+
450462
void Task::handle_output_enter(struct wl_output *output) {
451463
if (ignored_) {
452464
spdlog::debug("{} is ignored", repr());
@@ -457,6 +469,8 @@ void Task::handle_output_enter(struct wl_output *output) {
457469

458470
if (!button_visible_ && (tbar_->all_outputs() || tbar_->show_output(output))) {
459471
/* The task entered the output of the current bar make the button visible */
472+
button.signal_size_allocate().connect_notify(
473+
sigc::mem_fun(this, &Task::on_button_size_allocated));
460474
tbar_->add_button(button);
461475
button.show();
462476
button_visible_ = true;
@@ -553,9 +567,11 @@ bool Task::handle_clicked(GdkEventButton *bt) {
553567
return true;
554568
else if (action == "activate")
555569
activate();
556-
else if (action == "minimize")
570+
else if (action == "minimize") {
571+
set_minimize_hint();
557572
minimize(!minimized());
558-
else if (action == "minimize-raise") {
573+
} else if (action == "minimize-raise") {
574+
set_minimize_hint();
559575
if (minimized())
560576
minimize(false);
561577
else if (active())

0 commit comments

Comments
 (0)