11#include < giomm/desktopappinfo.h>
22#include < gtkmm/button.h>
3- #include < gtkmm/box .h>
3+ #include < gtkmm/hvbox .h>
44#include < gtkmm/icontheme.h>
55#include < gtkmm/image.h>
66
77#include < gdkmm/display.h>
88#include < gdkmm/seat.h>
9- #include < gdk/wayland/ gdkwayland.h>
9+ #include < gdk/gdkwayland.h>
1010
1111#include " dock.hpp"
1212#include " toplevel.hpp"
@@ -29,7 +29,6 @@ class WfToplevelIcon::impl
2929 wl_output *output;
3030
3131 uint32_t state;
32- bool closing = false ;
3332
3433 Gtk::Button button;
3534 Gtk::Image image;
@@ -42,13 +41,17 @@ class WfToplevelIcon::impl
4241 this ->handle = handle;
4342 this ->output = output;
4443
45- button.set_child (image);
44+ button.add (image);
4645 button.set_tooltip_text (" none" );
4746 button.get_style_context ()->add_class (" flat" );
48- button.get_style_context ()-> add_class ( " toplevel-icon " );
47+ button.show_all ( );
4948
50- button.signal_clicked ().connect (
51- sigc::mem_fun (*this , &WfToplevelIcon::impl::on_clicked));
49+ button.signal_clicked ().connect_notify (
50+ sigc::mem_fun (this , &WfToplevelIcon::impl::on_clicked));
51+ button.signal_size_allocate ().connect_notify (
52+ sigc::mem_fun (this , &WfToplevelIcon::impl::on_allocation_changed));
53+ button.property_scale_factor ().signal_changed ()
54+ .connect (sigc::mem_fun (this , &WfToplevelIcon::impl::on_scale_update));
5255
5356 auto dock = WfDockApp::get ().dock_for_wl_output (output);
5457 assert (dock); // ToplevelIcon is created only for existing outputs
@@ -57,11 +60,6 @@ class WfToplevelIcon::impl
5760
5861 void on_clicked ()
5962 {
60- if (closing)
61- {
62- return ;
63- }
64-
6563 if (!(state & WF_TOPLEVEL_STATE_ACTIVATED))
6664 {
6765 auto gseat = Gdk::Display::get_default ()->get_default_seat ();
@@ -80,13 +78,18 @@ class WfToplevelIcon::impl
8078 }
8179 }
8280
83- void set_app_id (std::string app_id )
81+ void on_allocation_changed (Gtk::Allocation& alloc )
8482 {
85- if (closing)
86- {
87- return ;
88- }
83+ send_rectangle_hint ();
84+ }
85+
86+ void on_scale_update ()
87+ {
88+ set_app_id (app_id);
89+ }
8990
91+ void set_app_id (std::string app_id)
92+ {
9093 this ->app_id = app_id;
9194 IconProvider::set_image_from_icon (image,
9295 app_id,
@@ -96,11 +99,6 @@ class WfToplevelIcon::impl
9699
97100 void send_rectangle_hint ()
98101 {
99- if (closing)
100- {
101- return ;
102- }
103-
104102 Gtk::Widget *widget = &this ->button ;
105103
106104 int x = 0 , y = 0 ;
@@ -126,55 +124,21 @@ class WfToplevelIcon::impl
126124
127125 void set_title (std::string title)
128126 {
129- if (closing)
130- {
131- return ;
132- }
133-
134127 button.set_tooltip_text (title);
135128 }
136129
137- void close ()
138- {
139- button.get_style_context ()->add_class (" closing" );
140- closing = true ;
141- }
142-
143130 void set_state (uint32_t state)
144131 {
145- if (closing)
146- {
147- return ;
148- }
149-
150132 bool was_activated = this ->state & WF_TOPLEVEL_STATE_ACTIVATED;
151133 this ->state = state;
152134 bool is_activated = this ->state & WF_TOPLEVEL_STATE_ACTIVATED;
153- bool is_min = state & WF_TOPLEVEL_STATE_MINIMIZED;
154- bool is_max = state & WF_TOPLEVEL_STATE_MAXIMIZED;
155- auto style = this ->button .get_style_context ();
135+
156136 if (!was_activated && is_activated)
157137 {
158- style ->remove_class (" flat" );
138+ this -> button . get_style_context () ->remove_class (" flat" );
159139 } else if (was_activated && !is_activated)
160140 {
161- style->add_class (" flat" );
162- }
163-
164- if (is_min)
165- {
166- style->add_class (" minimized" );
167- } else
168- {
169- style->remove_class (" minimized" );
170- }
171-
172- if (is_max)
173- {
174- style->add_class (" maximized" );
175- } else
176- {
177- style->remove_class (" maximized" );
141+ this ->button .get_style_context ()->add_class (" flat" );
178142 }
179143 }
180144
@@ -208,11 +172,6 @@ void WfToplevelIcon::set_state(uint32_t state)
208172 return pimpl->set_state (state);
209173}
210174
211- void WfToplevelIcon::close ()
212- {
213- return pimpl->close ();
214- }
215-
216175/* Icon loading functions */
217176namespace IconProvider
218177{
@@ -257,14 +216,20 @@ bool set_custom_icon(Gtk::Image& image, std::string app_id, int size, int scale)
257216 return false ;
258217 }
259218
260- image_set_icon (&image, custom_icons[app_id]);
219+ auto pb = load_icon_pixbuf_safe (custom_icons[app_id], size * scale);
220+ if (!pb.get ())
221+ {
222+ return false ;
223+ }
224+
225+ set_image_pixbuf (image, pb, scale);
261226 return true ;
262227}
263228
264229/* Gio::DesktopAppInfo
265230 *
266- * Usually knowing the app_id, we can get a desktop app info from Gio The filename is either the app_id +
267- * ".desktop" or lower_app_id + ".desktop" */
231+ * Usually knowing the app_id, we can get a desktop app info from Gio
232+ * The filename is either the app_id + ".desktop" or lower_app_id + ".desktop" */
268233Icon get_from_desktop_app_info (std::string app_id)
269234{
270235 Glib::RefPtr<Gio::DesktopAppInfo> app_info;
@@ -340,9 +305,8 @@ void set_image_from_icon(Gtk::Image& image,
340305
341306 bool found_icon = false ;
342307
343- /* Wayfire sends a list of app-id's in space separated format, other compositors send a single app-id, but
344- * in any case this works fine */
345- auto display = image.get_display ();
308+ /* Wayfire sends a list of app-id's in space separated format, other compositors
309+ * send a single app-id, but in any case this works fine */
346310 while (stream >> app_id)
347311 {
348312 /* Try first method: custom icon file provided by the user */
@@ -359,7 +323,7 @@ void set_image_from_icon(Gtk::Image& image,
359323 if (!icon)
360324 {
361325 /* Finally try directly looking up the icon, if it exists */
362- if (Gtk::IconTheme::get_for_display (display )->lookup_icon (app_id, 24 ))
326+ if (Gtk::IconTheme::get_default ( )->lookup_icon (app_id, 24 ))
363327 {
364328 icon_name = app_id;
365329 }
@@ -370,7 +334,7 @@ void set_image_from_icon(Gtk::Image& image,
370334
371335 WfIconLoadOptions options;
372336 options.user_scale = scale;
373- image_set_icon (& image, icon_name);
337+ set_image_icon ( image, icon_name, size, options );
374338
375339 /* finally found some icon */
376340 if (icon_name != " unknown" )
0 commit comments