Skip to content

Commit 3ecaaab

Browse files
committed
Added calendar widget
The widget is an embedded gtk4 calendar which can be styled as such. Written with the assistance of Qwen Code.
1 parent 1043ef9 commit 3ecaaab

7 files changed

Lines changed: 128 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ These widgets can be customized, added, removed and even reordered
9393
- Do Not Disturb
9494
- Notifications (Will always be visible)
9595
- Label
96+
- Calendar
9697
- Mpris (Media player controls for Spotify, Firefox, Chrome, etc...)
9798
- Menubar with dropdown and buttons
9899
- Button grid

data/style/style.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,5 @@ notificationwindow, blankwindow {
398398
@import "widgets/backlight";
399399
/* Inhibitors widget */
400400
@import "widgets/inhibitors";
401+
/* Calendar widget */
402+
@import "widgets/calendar";

data/style/widgets/calendar.scss

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Calendar widget styling
2+
.widget-calendar {
3+
padding: 12px;
4+
margin: 8px;
5+
6+
.day-label {
7+
font-size: 18px;
8+
font-weight: bold;
9+
color: var(--text-color);
10+
margin-bottom: 2px;
11+
}
12+
13+
.date-label {
14+
font-size: 14px;
15+
color: var(--text-color);
16+
opacity: 0.8;
17+
margin-bottom: 8px;
18+
}
19+
20+
calendar {
21+
background: rgba(var(--noti-bg), var(--noti-bg-alpha));
22+
border: var(--border);
23+
border-radius: var(--border-radius);
24+
padding: 8px;
25+
color: var(--text-color);
26+
font-size: 14px;
27+
}
28+
}

src/configSchema.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@
423423
"^inhibitors(#[a-zA-Z0-9_-]{1,}){0,1}?$": {
424424
"$comment": "References the widget structure from \"widgets\" below",
425425
"$ref": "#/widgets/inhibitors"
426+
},
427+
"^calendar(#[a-zA-Z0-9_-]{1,}){0,1}?$": {
428+
"$ref": "#/widgets/calendar"
426429
}
427430
}
428431
}
@@ -790,6 +793,23 @@
790793
"default": "Clear All"
791794
}
792795
}
796+
},
797+
"calendar": {
798+
"type": "object",
799+
"description": "Control Center Calendar Widget",
800+
"additionalProperties": false,
801+
"properties": {
802+
"show-day-label": {
803+
"type": "boolean",
804+
"description": "Whether to show the day label (e.g., \"Monday\")",
805+
"default": true
806+
},
807+
"show-date-label": {
808+
"type": "boolean",
809+
"description": "Whether to show the date label (e.g., \"January 1, 2024\")",
810+
"default": true
811+
}
812+
}
793813
}
794814
}
795815
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using GLib;
2+
3+
namespace SwayNotificationCenter.Widgets {
4+
public class Calendar : BaseWidget {
5+
public override string widget_name {
6+
get {
7+
return "calendar";
8+
}
9+
}
10+
11+
Gtk.Calendar calendar;
12+
Gtk.Label date_label;
13+
Gtk.Label day_label;
14+
15+
public Calendar (string suffix) {
16+
base (suffix);
17+
18+
Json.Object ?config = get_config (this);
19+
20+
var container = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
21+
container.set_margin_start (12);
22+
container.set_margin_end (12);
23+
container.set_margin_top (12);
24+
container.set_margin_bottom (12);
25+
container.set_hexpand (true);
26+
27+
day_label = new Gtk.Label ("");
28+
day_label.add_css_class ("day-label");
29+
day_label.set_halign (Gtk.Align.START);
30+
31+
date_label = new Gtk.Label ("");
32+
date_label.add_css_class ("date-label");
33+
date_label.set_halign (Gtk.Align.START);
34+
35+
calendar = new Gtk.Calendar ();
36+
calendar.set_hexpand (true);
37+
calendar.add_css_class ("calendar-widget");
38+
39+
if (config != null) {
40+
bool ?show_day_label = get_prop<bool> (config, "show-day-label", null);
41+
if (show_day_label == false) {
42+
day_label.hide ();
43+
}
44+
45+
bool ?show_date_label = get_prop<bool> (config, "show-date-label", null);
46+
if (show_date_label == false) {
47+
date_label.hide ();
48+
}
49+
}
50+
51+
container.append (day_label);
52+
container.append (date_label);
53+
container.append (calendar);
54+
append (container);
55+
56+
calendar.day_selected.connect (update_labels);
57+
update_labels ();
58+
}
59+
60+
void update_labels () {
61+
var now = new GLib.DateTime.now_local ();
62+
day_label.set_label (now.format ("%A"));
63+
date_label.set_label (now.format ("%B %-d, %Y"));
64+
}
65+
66+
public override void on_cc_visibility_change (bool value) {
67+
if (value) {
68+
update_labels ();
69+
}
70+
}
71+
}
72+
}

src/controlCenter/widgets/factory.vala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ namespace SwayNotificationCenter.Widgets {
3737
case "slider":
3838
widget = new Slider (suffix);
3939
break;
40+
case "calendar":
41+
widget = new Calendar (suffix);
42+
break;
4043
#if HAVE_PULSE_AUDIO
4144
case "volume":
4245
widget = new Volume (suffix);

src/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ widget_sources = [
5050
'controlCenter/widgets/backlight/backlightUtil.vala',
5151
# Widget: Inhibitors
5252
'controlCenter/widgets/inhibitors/inhibitors.vala',
53+
# Widget: Calendar
54+
'controlCenter/widgets/calendar/calendar.vala',
5355
]
5456

5557
app_sources = [

0 commit comments

Comments
 (0)