Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Add support for 3- and 4-line date+time display on vertical panels #1854

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1032,13 +1032,13 @@ var Panel = GObject.registerClass({
if (this.statusArea.dateMenu) {
let datetime = this.statusArea.dateMenu._clock.clock;
let datetimeParts = datetime.split(' ');
let date = datetimeParts[0];
let time = datetimeParts[1];
let clockText = this.statusArea.dateMenu._clockDisplay.clutter_text;
let setClockText = (text, useTimeSeparator) => {
let setClockText = text => {
let stacks = text instanceof Array;
let separator = `\n<span size="8192"> ${useTimeSeparator ? '‧‧' : '—' } </span>\n`;

clockText.set_text((stacks ? text.join(separator) : text).trim());
clockText.set_text((stacks ? text.join('\n') : text).trim());
clockText.set_use_markup(stacks);
clockText.get_allocation_box();

Expand All @@ -1055,23 +1055,50 @@ var Panel = GObject.registerClass({
if (!time) {
datetimeParts = datetime.split(' ');
time = datetimeParts.pop();
datetimeParts = [datetimeParts.join(' '), time];
date = datetimeParts.join(' ');
}

if (!setClockText(datetime) &&
!setClockText(datetimeParts) &&
!setClockText(time)) {
let timeParts = time.split('∶');
if (!setClockText(datetime)) {
let dtSep = '<span size="8192"> — </span>';

// Try a two-line date/time clock first
if (setClockText([date, dtSep, time])) {
return;
}

// Try a three-line clock: month/day/time
let dateParts = date.split(' ');
if (setClockText(dateParts.concat([dtSep, time]))) {
return;
}

// Set a multi-line clock with each piece on its own line

if (!this._clockFormat) {
this._clockFormat = Me.desktopSettings.get_string('clock-format');
}

let timeParts = time.split('∶');
let timeAMPM = '';
if (this._clockFormat == '12h') {
timeParts.push.apply(timeParts, timeParts.pop().split(' '));
timeParts = time.split(' ');
timeAMPM = timeParts[1];
timeParts = timeParts[0].split('∶');
}

let timeSep = '<span size="8192"> ‧‧ </span>';
let dtStack = dateParts.concat([dtSep]);
for (let timePart of timeParts) {
dtStack.push(timePart);
dtStack.push(timeSep);
}
if (this._clockFormat == '12h') {
dtStack.push(timeAMPM);
} else {
dtStack.pop();
}

setClockText(timeParts, true);
setClockText(dtStack);
}
}
}
Expand Down