@@ -3,6 +3,7 @@ const Gio = imports.gi.Gio;
33const GLib = imports . gi . GLib ;
44const Lang = imports . lang ;
55const Clutter = imports . gi . Clutter ;
6+ const Pango = imports . gi . Pango ;
67const St = imports . gi . St ;
78const Util = imports . misc . util ;
89const PopupMenu = imports . ui . popupMenu ;
@@ -20,7 +21,7 @@ const DAY_FORMAT = CinnamonDesktop.WallClock.lctime_format("cinnamon", "%A");
2021const DATE_FORMAT_SHORT = CinnamonDesktop . WallClock . lctime_format ( "cinnamon" , _ ( "%B %-e, %Y" ) ) ;
2122const DATE_FORMAT_FULL = CinnamonDesktop . WallClock . lctime_format ( "cinnamon" , _ ( "%A, %B %-e, %Y" ) ) ;
2223
23- class CinnamonCalendarApplet extends Applet . TextApplet {
24+ class CinnamonCalendarApplet extends Applet . Applet {
2425 constructor ( orientation , panel_height , instance_id ) {
2526 super ( orientation , panel_height , instance_id ) ;
2627
@@ -30,6 +31,19 @@ class CinnamonCalendarApplet extends Applet.TextApplet {
3031 this . menuManager = new PopupMenu . PopupMenuManager ( this ) ;
3132 this . orientation = orientation ;
3233
34+ this . _clockLabel = new St . Label ( {
35+ reactive : true ,
36+ track_hover : true ,
37+ style_class : 'applet-label'
38+ } ) ;
39+ this . _clockLabel . clutter_text . ellipsize = Pango . EllipsizeMode . NONE ;
40+
41+ this . _labelBin = new St . Bin ( ) ;
42+ this . _labelBin . set_child ( this . _clockLabel ) ;
43+
44+ this . actor . add ( this . _labelBin , { y_align : St . Align . MIDDLE , y_fill : false } ) ;
45+ this . actor . set_label_actor ( this . _clockLabel ) ;
46+
3347 this . _initContextMenu ( ) ;
3448 this . menu . setCustomStyleClass ( 'calendar-background' ) ;
3549
@@ -38,6 +52,8 @@ class CinnamonCalendarApplet extends Applet.TextApplet {
3852
3953 this . clock = new CinnamonDesktop . WallClock ( ) ;
4054 this . clock_notify_id = 0 ;
55+ this . theme_set_id = 0 ;
56+ this . panel_edit_mode_id = 0 ;
4157
4258 // Events
4359 this . events_manager = new EventView . EventsManager ( this . settings , this . desktop_settings ) ;
@@ -190,6 +206,8 @@ class CinnamonCalendarApplet extends Applet.TextApplet {
190206 }
191207
192208 _onSettingsChanged ( ) {
209+ this . _labelBin . min_width = 0 ;
210+
193211 this . _updateFormatString ( ) ;
194212 this . _updateClockAndDate ( ) ;
195213 this . event_list . actor . visible = this . events_manager . is_active ( ) ;
@@ -245,6 +263,44 @@ class CinnamonCalendarApplet extends Applet.TextApplet {
245263 }
246264 }
247265
266+ _onThemeSet ( ) {
267+ this . _resetLabelWidth ( ) ;
268+ }
269+
270+ _onPanelEditModeChanged ( ) {
271+ this . _resetLabelWidth ( ) ;
272+ }
273+
274+ on_panel_height_changed ( ) {
275+ this . _resetLabelWidth ( ) ;
276+ }
277+
278+ _resetLabelWidth ( ) {
279+ this . _labelBin . min_width = 0 ;
280+ this . _updateLabelWidth ( ) ;
281+ }
282+
283+ /* Grow to any wider string, but only snap back down when the width drops by
284+ * more than ~2 average character widths - ignores jitter from digit changes
285+ * while still reclaiming space when a whole word shrinks ("Saturday" -> "Sunday").
286+ *
287+ * We measure the label but force the min-width on the parent (_labelBin),
288+ * not the label itself, otherwise the label's natural width could never
289+ * shrink again. */
290+ _updateLabelWidth ( ) {
291+ let [ , natWidth ] = this . _clockLabel . get_preferred_width ( - 1 ) ;
292+ if ( natWidth <= 0 ) {
293+ return ;
294+ }
295+
296+ let avgChar = natWidth / Math . max ( 1 , this . _clockLabel . get_text ( ) . length ) ;
297+
298+ if ( natWidth > this . _labelBin . min_width ||
299+ natWidth < this . _labelBin . min_width - 2 * avgChar ) {
300+ this . _labelBin . min_width = natWidth ;
301+ }
302+ }
303+
248304 _events_manager_ready ( em ) {
249305 this . event_list . actor . visible = this . events_manager . is_active ( ) ;
250306 this . events_manager . select_date ( this . _calendar . getSelectedDate ( ) , true ) ;
@@ -264,8 +320,10 @@ class CinnamonCalendarApplet extends Applet.TextApplet {
264320 label_string = this . clock . get_clock_for_format ( this . custom_format ) ;
265321 }
266322
267- if ( label_string )
268- this . set_applet_label ( label_string ) ;
323+ if ( label_string ) {
324+ this . _clockLabel . set_text ( label_string ) ;
325+ this . _updateLabelWidth ( ) ;
326+ }
269327
270328 this . go_home_button . reactive = ! this . _calendar . todaySelected ( ) ;
271329 if ( this . _calendar . todaySelected ( ) ) {
@@ -303,6 +361,14 @@ class CinnamonCalendarApplet extends Applet.TextApplet {
303361 this . clock_notify_id = this . clock . connect ( "notify::clock" , ( ) => this . _clockNotify ( ) ) ;
304362 }
305363
364+ if ( this . theme_set_id == 0 ) {
365+ this . theme_set_id = Main . themeManager . connect ( "theme-set" , ( ) => this . _onThemeSet ( ) ) ;
366+ }
367+
368+ if ( this . panel_edit_mode_id == 0 ) {
369+ this . panel_edit_mode_id = global . settings . connect ( "changed::panel-edit-mode" , ( ) => this . _onPanelEditModeChanged ( ) ) ;
370+ }
371+
306372 /* Populates the calendar so our menu allocation is correct for animation */
307373 this . events_manager . start_events ( ) ;
308374 this . _resetCalendar ( ) ;
@@ -314,6 +380,14 @@ class CinnamonCalendarApplet extends Applet.TextApplet {
314380 this . clock . disconnect ( this . clock_notify_id ) ;
315381 this . clock_notify_id = 0 ;
316382 }
383+ if ( this . theme_set_id > 0 ) {
384+ Main . themeManager . disconnect ( this . theme_set_id ) ;
385+ this . theme_set_id = 0 ;
386+ }
387+ if ( this . panel_edit_mode_id > 0 ) {
388+ global . settings . disconnect ( this . panel_edit_mode_id ) ;
389+ this . panel_edit_mode_id = 0 ;
390+ }
317391 }
318392
319393 _initContextMenu ( ) {
0 commit comments