-
Notifications
You must be signed in to change notification settings - Fork 20
/
13-feature-linux-minimise-to-tray.patch
580 lines (548 loc) · 23 KB
/
13-feature-linux-minimise-to-tray.patch
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# HG changeset patch
# User Betterbird <betterbird@betterbird.eu>
# Date 1693170533 -10800
# Parent f0b6d399e0b4418760268794ba7f9ce96312ad74
Feature: Minimise to tray for Linux.
Adapted from
https://hg.mozilla.org/comm-central/rev/d9c8e04388eb
and
https://hg.mozilla.org/comm-central/rev/0bc379dfb518
* * *
Feature: Minimise to tray for Linux: Use native Gtk calls to restore windows to original position and size.
* * *
Feature: Minimise to tray for Linux: Fix activation of window.
* * *
Feature: Minimise to tray for Linux: Change GTK call from gtk_window_present() to gtk_window_present_with_time().
diff --git a/mail/app/profile/all-thunderbird.js b/mail/app/profile/all-thunderbird.js
--- a/mail/app/profile/all-thunderbird.js
+++ b/mail/app/profile/all-thunderbird.js
@@ -1338,19 +1338,22 @@ pref("toolkit.telemetry.updatePing.enabl
pref("toolkit.telemetry.bhrPing.enabled", true);
// Whether to enable Ecosystem Telemetry, requires a restart.
#ifdef NIGHTLY_BUILD
pref("toolkit.telemetry.ecosystemtelemetry.enabled", true);
#else
pref("toolkit.telemetry.ecosystemtelemetry.enabled", false);
#endif
-#ifdef XP_WIN
+#if defined(XP_WIN) || defined(UNIX_BUT_NOT_MAC)
pref("mail.minimizeToTray", false);
#endif
+#ifdef UNIX_BUT_NOT_MAC
+pref("mail.minimizeToTray.supportedDesktops", "kde,gnome,xfce");
+#endif
pref("prompts.defaultModalType", 3);
pref("prompts.contentPromptSubDialog", false);
// The URL for the privacy policy related to recommended extensions.
pref("extensions.recommendations.privacyPolicyUrl", "https://www.mozilla.org/en-US/privacy/thunderbird/#addons");
// Used by pdf.js to know the first time Thunderbird is run with it installed
diff --git a/mail/base/content/messenger.xhtml b/mail/base/content/messenger.xhtml
--- a/mail/base/content/messenger.xhtml
+++ b/mail/base/content/messenger.xhtml
@@ -143,19 +143,21 @@
<script defer="defer" src="chrome://messenger/content/sync.js"></script>
#endif
<!-- panelUI.js is for the appmenus. -->
<script defer="defer" src="chrome://messenger/content/panelUI.js"></script>
#ifdef XP_MACOSX
<script defer="defer" src="chrome://messenger/content/macMessengerMenu.js"></script>
<script defer="defer" src="chrome://global/content/macWindowMenu.js"></script>
#endif
-#ifdef XP_WIN
+#if defined(XP_WIN) || defined(XP_UNIX)
+#ifndef XP_MACOSX
<script defer="defer" src="chrome://messenger/content/minimizeToTray.js"></script>
#endif
+#endif
<!-- calendar-management.js also needed for multiple calendar support and today pane -->
<script defer="defer" src="chrome://calendar/content/calendar-management.js"></script>
<script defer="defer" src="chrome://calendar/content/calendar-ui-utils.js"></script>
<script defer="defer" src="chrome://calendar/content/calendar-tabs.js"></script>
<script defer="defer" src="chrome://calendar/content/calendar-modes.js"></script>
<script defer="defer" src="chrome://calendar/content/calendar-day-label.js"></script>
diff --git a/mail/base/content/minimizeToTray.js b/mail/base/content/minimizeToTray.js
--- a/mail/base/content/minimizeToTray.js
+++ b/mail/base/content/minimizeToTray.js
@@ -1,19 +1,23 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
/* globals docShell, Services, windowState */
+var { AppConstants } = ChromeUtils.import(
+ "resource://gre/modules/AppConstants.jsm"
+);
+
addEventListener("sizemodechange", () => {
if (
windowState == window.STATE_MINIMIZED &&
Services.prefs.getBoolPref("mail.minimizeToTray", false)
) {
setTimeout(() => {
var bw = docShell.treeOwner.QueryInterface(Ci.nsIBaseWindow);
Cc["@mozilla.org/messenger/osintegration;1"]
- .getService(Ci.nsIMessengerWindowsIntegration)
+ .getService(AppConstants.platform == "win" ? Ci.nsIMessengerWindowsIntegration : Ci.nsIMessengerUnixIntegration)
.hideWindow(bw);
});
}
});
diff --git a/mail/base/jar.mn b/mail/base/jar.mn
--- a/mail/base/jar.mn
+++ b/mail/base/jar.mn
@@ -52,17 +52,17 @@ messenger.jar:
content/messenger/mailWindow.js (content/mailWindow.js)
content/messenger/mailWindowOverlay.js (content/mailWindowOverlay.js)
content/messenger/messageWindow.js (content/messageWindow.js)
* content/messenger/messageWindow.xhtml (content/messageWindow.xhtml)
content/messenger/messenger-customization.js (content/messenger-customization.js)
content/messenger/messenger.js (content/messenger.js)
* content/messenger/messenger.xhtml (content/messenger.xhtml)
content/messenger/webextensions.css (content/webextensions.css)
-#ifdef XP_WIN
+#if defined(XP_WIN) || defined(XP_LINUX)
content/messenger/minimizeToTray.js (content/minimizeToTray.js)
#endif
content/messenger/migrationProgress.js (content/migrationProgress.js)
content/messenger/migrationProgress.xhtml (content/migrationProgress.xhtml)
content/messenger/msgHdrView.js (content/msgHdrView.js)
content/messenger/msgSecurityPane.js (content/msgSecurityPane.js)
content/messenger/msgViewNavigation.js (content/msgViewNavigation.js)
content/messenger/multimessageview.js (content/multimessageview.js)
diff --git a/mail/components/preferences/general.inc.xhtml b/mail/components/preferences/general.inc.xhtml
--- a/mail/components/preferences/general.inc.xhtml
+++ b/mail/components/preferences/general.inc.xhtml
@@ -99,22 +99,24 @@
unset-default-tooltip,
checkbox-email-label.label,
checkbox-newsgroups-label.label,
checkbox-feeds-label.label,
system-search-integration-label.label,
check-on-startup-label.label"/>
</hbox>
</hbox>
-#ifdef XP_WIN
+#if defined(XP_WIN) || defined(XP_UNIX)
+#ifndef XP_MACOSX
<hbox align="start">
<checkbox data-l10n-id="minimize-to-tray-label"
preference="mail.minimizeToTray"/>
</hbox>
#endif
+#endif
<hbox id="searchIntegrationContainer">
<checkbox id="searchIntegration"
preference="searchintegration.enable"
data-l10n-id="search-integration-label"/>
</hbox>
</vbox>
</html:fieldset>
</html:div>
diff --git a/mail/components/preferences/general.js b/mail/components/preferences/general.js
--- a/mail/components/preferences/general.js
+++ b/mail/components/preferences/general.js
@@ -91,17 +91,17 @@ Preferences.addAll([
{ id: "privacy.clearOnShutdown.cache", type: "bool" },
{ id: "layers.acceleration.disabled", type: "bool", inverted: true },
{ id: "searchintegration.enable", type: "bool" },
{ id: "mail.tabs.drawInTitlebar", type: "bool" },
{ id: "mail.tabs.autoHide", type: "bool" },
{ id: "mail.tabs.vertical", type: "bool" },
{ id: "mailnews.attachments.display.top", type: "bool" },
]);
-if (AppConstants.platform == "win") {
+if (AppConstants.platform == "win" || AppConstants.platform == "linux") {
Preferences.add({ id: "mail.minimizeToTray", type: "bool" });
}
if (AppConstants.platform != "macosx") {
Preferences.add({ id: "mail.biff.show_alert", type: "bool" });
}
var ICON_URL_APP = "";
diff --git a/mail/modules/MailUtils.jsm b/mail/modules/MailUtils.jsm
--- a/mail/modules/MailUtils.jsm
+++ b/mail/modules/MailUtils.jsm
@@ -368,16 +368,20 @@ var MailUtils = {
return;
}
}
if (Ci.nsIMessengerWindowsIntegration) {
Cc["@mozilla.org/messenger/osintegration;1"]
.getService(Ci.nsIMessengerWindowsIntegration)
.showWindow(mail3PaneWindow);
+ } else if (Ci.nsIMessengerUnixIntegration) {
+ Cc["@mozilla.org/messenger/osintegration;1"]
+ .getService(Ci.nsIMessengerUnixIntegration)
+ .showWindow(mail3PaneWindow);
}
mail3PaneWindow.focus();
} else {
let args = { msgHdr };
args.wrappedJSObject = args;
Services.ww.openWindow(
null,
"chrome://messenger/content/messenger.xhtml",
diff --git a/mailnews/base/public/moz.build b/mailnews/base/public/moz.build
--- a/mailnews/base/public/moz.build
+++ b/mailnews/base/public/moz.build
@@ -65,16 +65,21 @@ XPIDL_SOURCES += [
"nsMsgMessageFlags.idl",
]
if CONFIG["OS_ARCH"] == "WINNT":
XPIDL_SOURCES += [
"nsIMessengerWindowsIntegration.idl",
]
+if CONFIG["OS_ARCH"] == "Linux":
+ XPIDL_SOURCES += [
+ "nsIMessengerUnixIntegration.idl",
+ ]
+
XPIDL_MODULE = "msgbase"
EXPORTS += [
"MailNewsTypes.h",
"msgCore.h",
"nsMsgHeaderMasks.h",
"nsMsgLocalFolderHdrs.h",
]
diff --git a/mailnews/base/public/nsIMessengerUnixIntegration.idl b/mailnews/base/public/nsIMessengerUnixIntegration.idl
new file mode 100644
--- /dev/null
+++ b/mailnews/base/public/nsIMessengerUnixIntegration.idl
@@ -0,0 +1,16 @@
+/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+interface mozIDOMWindowProxy;
+
+#include "nsIBaseWindow.idl"
+#include "nsIMessengerOSIntegration.idl"
+
+/* GUID from https://www.guidgenerator.com/online-guid-generator.aspx */
+[scriptable, uuid(ea26454c-2d5e-498c-87f0-95f93c51b8e6)]
+interface nsIMessengerUnixIntegration : nsIMessengerOSIntegration {
+ void hideWindow(in nsIBaseWindow aWindow);
+ void showWindow(in mozIDOMWindowProxy aWindow);
+};
diff --git a/mailnews/base/src/nsMessengerUnixIntegration.cpp b/mailnews/base/src/nsMessengerUnixIntegration.cpp
--- a/mailnews/base/src/nsMessengerUnixIntegration.cpp
+++ b/mailnews/base/src/nsMessengerUnixIntegration.cpp
@@ -1,66 +1,302 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMessengerUnixIntegration.h"
+#include "nsServiceManagerUtils.h"
+#include "nsCOMPtr.h"
+#include "nsCOMArray.h"
#include "nsString.h"
#include "../../../third_party/appindicator/app-indicator.h"
#include "mozilla/Preferences.h"
+#include "mozIDOMWindow.h"
+#include "nsIBaseWindow.h"
+#include "nsIDocShell.h"
+#include "nsIPrefService.h"
+#include "nsIWidget.h"
+#include "mozilla/WidgetUtilsGtk.h"
+#include "nsIWindowMediator.h"
+#include "nsPIDOMWindow.h"
+#include <time.h>
+
+#define SHOW_TRAY_ICON_PREF "mail.biff.show_tray_icon"
+#define SHOW_TRAY_ICON_ALWAYS_PREF "mail.biff.show_tray_icon_always"
+
+typedef struct {
+ int32_t x;
+ int32_t y;
+ int32_t w;
+ int32_t h;
+} WinDims;
+static nsCOMArray<nsIBaseWindow> sHiddenWindows;
+static nsTArray<WinDims> sHiddenWindowsDims;
+static uint32_t sLastUnreadCount;
+static nsAutoString sLastUnreadTooltip;
+static AppIndicator *ci = NULL;
+static struct timespec sTimeActivated;
+
+using namespace mozilla;
nsMessengerUnixIntegration::nsMessengerUnixIntegration() {}
-NS_IMPL_ISUPPORTS(nsMessengerUnixIntegration, nsIMessengerOSIntegration)
+NS_IMPL_ADDREF(nsMessengerUnixIntegration)
+NS_IMPL_RELEASE(nsMessengerUnixIntegration)
+
+NS_INTERFACE_MAP_BEGIN(nsMessengerUnixIntegration)
+ NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMessengerOSIntegration)
+ NS_INTERFACE_MAP_ENTRY(nsIMessengerUnixIntegration)
+ NS_INTERFACE_MAP_ENTRY(nsIMessengerOSIntegration)
+NS_INTERFACE_MAP_END
+
+static void activateWindow(mozIDOMWindowProxy* win) {
+ nsCOMPtr<nsPIDOMWindowOuter> domWindow = nsPIDOMWindowOuter::From(win);
+ nsCOMPtr<nsIBaseWindow> baseWindow =
+ do_QueryInterface(domWindow->GetDocShell());
+ if (!baseWindow) {
+ domWindow->Focus(mozilla::dom::CallerType::System);
+ fprintf(stderr, "Betterbird: Activating window via Focus() only (1)\n");
+ return;
+ }
+ // Getting the visibility doesn't work, even hidden windows are visible :-(
+ baseWindow->SetVisibility(true);
+
+ nsCOMPtr<nsIWidget> widget;
+ baseWindow->GetMainWidget(getter_AddRefs(widget));
+ if (!widget) {
+ fprintf(stderr, "Betterbird: Activating window via Focus() only (2)\n");
+ return;
+ }
+
+ // Raise the window, no good if it appears in the background.
+ // KDE works with just the `SetFocus()`, `gtk_window_present` was added for Gnome.
+ void* gtkWidget = widget->GetNativeData(NS_NATIVE_SHELLWIDGET);
+ if (gtkWidget) gtk_window_present_with_time(GTK_WINDOW(gtkWidget), (guint32)(g_get_monotonic_time() / 1000));
+ widget->SetFocus(nsIWidget::Raise::Yes, mozilla::dom::CallerType::System);
+
+ // Now move the window to where it was. We need to find it first in the
+ // list of windows.
+ if (!gtkWidget) {
+ fprintf(stderr, "Betterbird: Activating window via Focus() only (3)\n");
+ return;
+ }
+ for (uint32_t i = 0; i < sHiddenWindows.Length(); i++) {
+ auto window = sHiddenWindows.SafeElementAt(i);
+ if (!window) {
+ continue;
+ }
+ nsCOMPtr<nsIWidget> w;
+ window->GetMainWidget(getter_AddRefs(w));
+ if (widget == w) {
+ WinDims dims = sHiddenWindowsDims[i];
+ // The following isn't working well, so use native calls.
+ // Last parameter: Bits: eRepaint = 1; eDelayResize = 2;
+ // window->SetPositionAndSize(dims.x, dims.y, dims.w, dims.h, 1);
+ gtk_window_move(GTK_WINDOW(gtkWidget), dims.x, dims.y);
+ gtk_window_resize(GTK_WINDOW(gtkWidget), dims.w, dims.h);
+// #define DEBUG_RESTORE 1
+#ifdef DEBUG_RESTORE
+ fprintf(stderr, "=== Trying to restore to %d %d %d %d\n", dims.x, dims.y, dims.w, dims.h);
+ // window->GetPositionAndSize(&dims.x, &dims.y, &dims.w, &dims.h);
+ gtk_window_get_position(GTK_WINDOW(gtkWidget), &dims.x, &dims.y);
+ gtk_window_get_size(GTK_WINDOW(gtkWidget), &dims.w, &dims.h);
+ fprintf(stderr, "=== was restored to %d %d %d %d\n", dims.x, dims.y, dims.w, dims.h);
+#endif
+ sHiddenWindows.RemoveElementAt(i);
+ sHiddenWindowsDims.RemoveElementAt(i);
+ break;
+ }
+ }
+
+ // Strangely we get "sizemodechange" event with STATE_MINIMIZED,
+ // so we ignore that for some milliseconds.
+ clock_gettime(CLOCK_MONOTONIC, &sTimeActivated);
+}
+
+static void activated(AppIndicator* self, gint x, gint y, gpointer data) {
+ nsresult rv;
+ bool showTrayIcon = mozilla::Preferences::GetBool(SHOW_TRAY_ICON_PREF, false);
+ bool showTrayIconAlways = mozilla::Preferences::GetBool(SHOW_TRAY_ICON_ALWAYS_PREF, false);
+ if ((!showTrayIcon || !sLastUnreadCount) && !showTrayIconAlways) {
+ if (ci) {
+ app_indicator_set_status(ci, APP_INDICATOR_STATUS_PASSIVE);
+ }
+ }
+
+ // No minimized window, bring the most recent 3pane window to the front.
+ if (sHiddenWindows.Length() == 0) {
+ nsCOMPtr<nsIWindowMediator> windowMediator =
+ do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
+ NS_ENSURE_SUCCESS_VOID(rv);
+
+ nsCOMPtr<mozIDOMWindowProxy> domWindow;
+ rv = windowMediator->GetMostRecentWindow(u"mail:3pane",
+ getter_AddRefs(domWindow));
+ NS_ENSURE_SUCCESS_VOID(rv);
+ if (domWindow) {
+ activateWindow(domWindow);
+ return;
+ }
+ }
+
+ // Bring the minimized windows to the front.
+ for (uint32_t i = 0; i < sHiddenWindows.Length(); i++) {
+ auto window = sHiddenWindows.SafeElementAt(i);
+ if (!window) {
+ continue;
+ }
+ window->SetVisibility(true);
+
+ nsCOMPtr<nsIWidget> widget;
+ window->GetMainWidget(getter_AddRefs(widget));
+ if (!widget) {
+ continue;
+ }
+ // Raise the window, no good if it appears in the background.
+ // KDE works with just the `SetFocus()`, `gtk_window_present` was added for Gnome.
+ void* gtkWidget = widget->GetNativeData(NS_NATIVE_SHELLWIDGET);
+ if (gtkWidget) gtk_window_present_with_time(GTK_WINDOW(gtkWidget), (guint32)(g_get_monotonic_time() / 1000));
+ widget->SetFocus(nsIWidget::Raise::Yes, mozilla::dom::CallerType::System);
+
+ WinDims dims = sHiddenWindowsDims[i];
+ // The following isn't working well, so use native calls.
+ // Last parameter: Bits: eRepaint = 1; eDelayResize = 2;
+ // window->SetPositionAndSize(dims.x, dims.y, dims.w, dims.h, 1);
+ if (gtkWidget) {
+ gtk_window_move(GTK_WINDOW(gtkWidget), dims.x, dims.y);
+ gtk_window_resize(GTK_WINDOW(gtkWidget), dims.w, dims.h);
+// #define DEBUG_RESTORE 1
+#ifdef DEBUG_RESTORE
+ fprintf(stderr, "=== Trying to restore to %d %d %d %d\n", dims.x, dims.y, dims.w, dims.h);
+ // window->GetPositionAndSize(&dims.x, &dims.y, &dims.w, &dims.h);
+ gtk_window_get_position(GTK_WINDOW(gtkWidget), &dims.x, &dims.y);
+ gtk_window_get_size(GTK_WINDOW(gtkWidget), &dims.w, &dims.h);
+ fprintf(stderr, "=== was restored to %d %d %d %d\n", dims.x, dims.y, dims.w, dims.h);
+#endif
+ }
+ }
+
+ sHiddenWindows.Clear();
+ sHiddenWindowsDims.Clear();
+ // Strangely we get "sizemodechange" event with STATE_MINIMIZED,
+ // so we ignore that for some milliseconds.
+ clock_gettime(CLOCK_MONOTONIC, &sTimeActivated);
+}
NS_IMETHODIMP
nsMessengerUnixIntegration::UpdateUnreadCount(uint32_t unreadCount,
const nsAString& unreadTooltip) {
- if (!mozilla::Preferences::GetBool("mail.biff.show_tray_icon", false)) return NS_OK;
+ sLastUnreadCount = unreadCount;
+ sLastUnreadTooltip = unreadTooltip;
- static AppIndicator *ci = NULL;
+ if (!mozilla::Preferences::GetBool("mail.biff.show_tray_icon", false) &&
+ sHiddenWindows.Length() == 0) return NS_OK;
+
static char icon_path0[PATH_MAX + 100];
static char icon_pathN[PATH_MAX + 100];
if (!ci) {
// Find icon absolute path.
size_t len = readlink("/proc/self/exe", icon_path0, PATH_MAX);
char* q = icon_path0 + len - 1;
while (*q != '/') q--;
*q = 0;
strcpy(icon_pathN, icon_path0);
strcat(icon_path0, "/chrome/icons/default/default.svg");
strcat(icon_pathN, "/chrome/icons/default/newmail.svg");
ci = app_indicator_new("Betterbird-systray-icon",
unreadCount > 0 ? icon_pathN : icon_path0,
APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
+ g_signal_connect(ci, APP_INDICATOR_SIGNAL_ACTIVATE_EVENT, G_CALLBACK(activated), NULL);
+
+ // Initialise to something non-zero, subtract a second
+ // so it predates any mimizing via "startup minimized".
+ clock_gettime(CLOCK_MONOTONIC, &sTimeActivated);
+ sTimeActivated.tv_sec--;
}
if (unreadCount > 0) {
const nsCString& tooltip = NS_ConvertUTF16toUTF8(unreadTooltip);
// Set both title and tooltip. It appears that some platforms do
// one but not the other.
app_indicator_set_title(ci, tooltip.get());
app_indicator_set_tooltip_full(ci,
NULL /* icon */, tooltip.get() /* title */, NULL /* body */
);
app_indicator_set_icon_full(ci, icon_pathN, NULL);
app_indicator_set_status(ci, APP_INDICATOR_STATUS_ACTIVE);
} else {
- if (mozilla::Preferences::GetBool("mail.biff.show_tray_icon_always", false)) {
+ if (mozilla::Preferences::GetBool("mail.biff.show_tray_icon_always", false) ||
+ sHiddenWindows.Length() > 0) {
app_indicator_set_title(ci, "Betterbird");
app_indicator_set_tooltip_full(ci,
NULL /* icon */, "Betterbird" /* title */, NULL /* body */
);
app_indicator_set_icon_full(ci, icon_path0, NULL);
app_indicator_set_status(ci, APP_INDICATOR_STATUS_ACTIVE);
} else {
app_indicator_set_status(ci, APP_INDICATOR_STATUS_PASSIVE);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsMessengerUnixIntegration::OnExit() { return NS_OK; }
+
+nsresult nsMessengerUnixIntegration::HideWindow(nsIBaseWindow* aWindow) {
+ NS_ENSURE_ARG(aWindow);
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ // Ignore any hiding for 500ms.
+ int64_t timediff =
+ (now.tv_sec - sTimeActivated.tv_sec) * 1000 +
+ (now.tv_nsec - sTimeActivated.tv_nsec) / 1000000;
+ if (timediff < 500) {
+ return NS_OK;
+ }
+
+ nsAutoCString prefValue;
+ mozilla::Preferences::GetCString("mail.minimizeToTray.supportedDesktops", prefValue);
+ const nsCString& desktop = mozilla::widget::GetDesktopEnvironmentIdentifier();
+ if (!FindInReadable(desktop, prefValue)) {
+ fprintf(stderr, "Betterbird: Window NOT minimized to system tray!\n");
+ fprintf(stderr, " You are using desktop environment %s.\n", desktop.get());
+ fprintf(stderr, " Minimize to system tray is only supported for these desktops:\n");
+ fprintf(stderr, " %s.\n", prefValue.get());
+ fprintf(stderr, " As an experiment, add %s to preference\n", desktop.get());
+ fprintf(stderr, " mail.minimizeToTray.supportedDesktops.\n");
+ fprintf(stderr, " You might not be able to maximize the window again and\n");
+ fprintf(stderr, " will have to kill Betterbird.\n");
+ fprintf(stderr, " USE AT YOUR OWN RISK! If successful, contact support@betterbird.eu\n\n");
+ return NS_OK;
+ }
+ WinDims dims;
+ // The following isn't working well, so use native calls.
+ // aWindow->GetPositionAndSize(&dims.x, &dims.y, &dims.w, &dims.h);
+ nsCOMPtr<nsIWidget> widget;
+ aWindow->GetMainWidget(getter_AddRefs(widget));
+ if (widget) {
+ void* gtkWidget = widget->GetNativeData(NS_NATIVE_SHELLWIDGET);
+ if (gtkWidget) {
+ gtk_window_get_position(GTK_WINDOW(gtkWidget), &dims.x, &dims.y);
+ gtk_window_get_size(GTK_WINDOW(gtkWidget), &dims.w, &dims.h);
+#ifdef DEBUG_RESTORE
+ fprintf(stderr, "=== Was at %d %d %d %d\n", dims.x, dims.y, dims.w, dims.h);
+#endif
+ }
+ }
+ aWindow->SetVisibility(false);
+ sHiddenWindows.AppendElement(aWindow);
+ sHiddenWindowsDims.AppendElement(dims);
+ UpdateUnreadCount(sLastUnreadCount, sLastUnreadTooltip);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsMessengerUnixIntegration::ShowWindow(mozIDOMWindowProxy* aWindow) {
+ activateWindow(aWindow);
+ return NS_OK;
+}
diff --git a/mailnews/base/src/nsMessengerUnixIntegration.h b/mailnews/base/src/nsMessengerUnixIntegration.h
--- a/mailnews/base/src/nsMessengerUnixIntegration.h
+++ b/mailnews/base/src/nsMessengerUnixIntegration.h
@@ -1,22 +1,23 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef __nsMessengerUnixIntegration_h
#define __nsMessengerUnixIntegration_h
-#include "nsIMessengerOSIntegration.h"
+#include "nsIMessengerUnixIntegration.h"
-class nsMessengerUnixIntegration : public nsIMessengerOSIntegration {
+class nsMessengerUnixIntegration : public nsIMessengerUnixIntegration {
public:
nsMessengerUnixIntegration();
NS_DECL_ISUPPORTS
NS_DECL_NSIMESSENGEROSINTEGRATION
+ NS_DECL_NSIMESSENGERUNIXINTEGRATION
private:
virtual ~nsMessengerUnixIntegration() {}
};
#endif // __nsMessengerUnixIntegration_h