Repository navigation
Expand file tree
/
Copy pathdateButton.js
More file actions
211 lines (187 loc) · 7.35 KB
/
Copy pathdateButton.js
File metadata and controls
211 lines (187 loc) · 7.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
* Floating-Mini-Panel for GNOME Shell 46+
*
* Copyright 2024, 2025 Gerhard Himmel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
import Clutter from 'gi://Clutter';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Shell from 'gi://Shell';
import St from 'gi://St';
import * as Config from 'resource:///org/gnome/shell/misc/config.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
const PANELBOX = Main.layoutManager.panelBox;
const DATEMENU = Main.panel.statusArea['dateMenu'];
const DATESOURCEACTOR = DATEMENU.menu.sourceActor;
const DATEARROWALIGNMENT = DATEMENU.menu._arrowAlignment;
const shellVersion = parseFloat(Config.PACKAGE_VERSION);
export const DateButton = GObject.registerClass(
class DateButton extends St.BoxLayout {
constructor(parent) {
super({
name: 'dateBtn',
reactive: true,
track_hover: true,
style_class: 'button btn',
});
this._parent = parent;
// START CODE VERTICAL
this.orientStr = shellVersion > 47 ? 'orientation' : 'vertical';
this._parent.bind_property_full(
this.orientStr,
this,
this.orientStr,
GObject.BindingFlags.SYNC_CREATE,
(binding, value) => {
if (value) {
DATEMENU.menu._boxPointer._userArrowSide = St.Side.LEFT;
} else {
DATEMENU.menu._boxPointer._userArrowSide = St.Side.TOP;
}
return [binding, value];
},
null
);
this.connect('notify::mapped', () => {
DATEMENU.menu.close();
if (this.mapped) {
DATEMENU.menu.sourceActor = this;
DATEMENU.menu._arrowAlignment = 0.5;
// START CODE VERTICAL
if (this[this.orientStr])
DATEMENU.menu._boxPointer._userArrowSide = St.Side.LEFT;
} else {
DATEMENU.menu.sourceActor = DATESOURCEACTOR;
DATEMENU.menu._arrowAlignment = DATEARROWALIGNMENT;
// START CODE VERTICAL
DATEMENU.menu._boxPointer._userArrowSide = St.Side.TOP;
}
});
this.connect('button-press-event', () => {
DATEMENU.menu.toggle();
});
this._dmConId = DATEMENU.menu.connect('open-state-changed', () => {
if (this.has_style_pseudo_class('active')) {
this.remove_style_pseudo_class('active');
} else {
this.add_style_pseudo_class('active');
}
return GLib.SOURCE_PROPAGATE;
});
// START CODE VERTICAL
function formatDate(vertical) {
let dateStr = DATEMENU._clockDisplay.text;
if (vertical) {
// Divide date from time and replace spaces with newlines
dateStr = dateStr
.replace(/\u2002/g, '\n――\n')
.replace(/\s/g, '\n');
// Seconds are active
if (
dateStr.split(':').length > 2 ||
dateStr.split('∶').length > 2
) {
dateStr = dateStr.replace(/:|∶/g, '\n𐤟 𐤟\n');
} else {
dateStr = dateStr.replace(/\n――/g, '');
}
// If 12h mode
dateStr = dateStr.replace(/\n\n/g, '\n');
// If 12h mode and time only
if (dateStr[0] === '\n') dateStr = dateStr.substring(1);
}
return dateStr;
}
this._dateLabel = new St.Label({
// START CODE VERTICAL
text: formatDate(this[this.orientStr]),
x_expand: true,
x_align: Clutter.ActorAlign.CENTER,
y_expand: true,
y_align: Clutter.ActorAlign.CENTER,
style: 'padding-top: 2px;', // Align with percentage label
});
this.add_child(this._dateLabel);
// START CODE VERTICAL
this.connect('notify::' + this.orientStr, () => {
this._dateLabel.text = formatDate(this[this.orientStr]);
});
this._dateConId = DATEMENU._clockDisplay.bind_property_full(
'text',
this._dateLabel,
'text',
GObject.Binding.CREATE_SYNC,
// START CODE VERTICAL
() => {
return [String, formatDate(this[this.orientStr])];
},
null
);
this._noteIcon = new St.Icon({
style_class: 'system-status-icon',
visible: DATEMENU._indicator.visible,
});
this.add_child(this._noteIcon);
this._noteConId1 = DATEMENU._indicator.bind_property(
'icon-name',
this._noteIcon,
'icon-name',
GObject.Binding.CREATE_SYNC
);
this._noteConId2 = DATEMENU._indicator.bind_property(
'visible',
this._noteIcon,
'visible',
GObject.Binding.CREATE_SYNC
);
Main.wm.setCustomKeybindingHandler(
'toggle-message-tray',
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW |
Shell.ActionMode.POPUP,
this._toggleCalendar.bind(this)
);
}
_toggleCalendar() {
if (this.visible || PANELBOX.visible) {
DATEMENU.menu.toggle();
if (DATEMENU.menu.isOpen) {
DATEMENU.menu.actor.navigate_focus(
null,
St.DirectionType.TAB_FORWARD,
false
);
}
}
}
destroy() {
Main.wm.setCustomKeybindingHandler(
'toggle-message-tray',
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW |
Shell.ActionMode.POPUP,
Main.wm._toggleCalendar.bind(Main.wm)
);
this._dateConId = null;
this._noteConId1 = null;
this._noteConId2 = null;
DATEMENU.menu.disconnect(this._dmConId);
this._dmConId = null;
super.destroy();
}
}
);