-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindicator.js
More file actions
2718 lines (2373 loc) · 97.4 KB
/
Copy pathindicator.js
File metadata and controls
2718 lines (2373 loc) · 97.4 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
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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* indicator.js
*
* Main panel indicator for Praya extension
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import GObject from 'gi://GObject';
import GLib from 'gi://GLib';
import St from 'gi://St';
import Gio from 'gi://Gio';
import GioUnix from 'gi://GioUnix';
import Shell from 'gi://Shell';
import Clutter from 'gi://Clutter';
import AccountsService from 'gi://AccountsService';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
import * as SystemActions from 'resource:///org/gnome/shell/misc/systemActions.js';
import { _ } from './translations.js';
import { ChatbotSettings, PrayaChatbotPanel } from './chatbot.js';
import { connectClickHandler } from './touch-helper.js';
import {
PANEL_WIDTH,
HEADER_HEIGHT,
ANIMATION_DURATION,
MARGIN_LEFT,
MARGIN_TOP,
MARGIN_BOTTOM,
MARGIN_BOTTOM_BAR,
CHATBOT_PANEL_WIDTH,
FAVOURITES_FILE
} from './constants.js';
export const PrayaIndicator = GObject.registerClass(
class PrayaIndicator extends PanelMenu.Button {
_init() {
super._init(0.0, 'Praya Menu');
// Create a box to hold the logo
let box = new St.BoxLayout({style_class: 'panel-status-menu-box'});
// Add logo using St.Widget with CSS background
let logo = new St.Widget({
style_class: 'praya-panel-logo',
y_align: Clutter.ActorAlign.CENTER,
});
box.add_child(logo);
this.add_child(box);
// Track panel visibility
this._panelVisible = false;
this._isPanelTransitioning = false;
this._panel = null;
this._hoverZone = null;
this._navigationStack = [];
this._isAnimating = false;
this._hoverTimeoutId = null;
this._isSearchActive = false;
this._searchEntry = null;
this._keyPressId = null;
// Keyboard navigation
this._focusedIndex = -1;
this._menuItems = [];
this._menuBox = null;
// Load applications data
this._categories = {};
this._appSystem = Shell.AppSystem.get_default();
// Favourites
this._favourites = [];
this._loadFavourites();
// Context menu for right-click
this._contextMenu = null;
// System actions for power menu
this._systemActions = SystemActions.getDefault();
// Chatbot state
this._chatbotSettings = new ChatbotSettings();
this._isChatbotMode = false;
this._chatbotPanel = null;
this._chatbotMessages = []; // Preserve messages across panel hide/show
this._isTransitioningChatbot = false; // Prevent panel hide during transition
this._servicesConfig = this._loadServicesConfig(); // Load AI enabled state
this._mainMenuHoverActivate = this._servicesConfig.mainMenuHoverActivate || false;
// Multi-monitor support - track which monitor the panel is on
this._currentMonitor = null;
// Delay initial load to ensure shell is ready (1 second)
this._loadAppsTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
this._loadApplicationsData();
this._loadAppsTimeoutId = null;
return GLib.SOURCE_REMOVE;
});
// Reload apps when installed apps change
this._installedChangedId = this._appSystem.connect('installed-changed', () => {
this._loadApplicationsData();
});
// Connect hover handler to show panel (only if enabled in config)
this.connect('enter-event', () => {
if (!this._mainMenuHoverActivate) return Clutter.EVENT_PROPAGATE;
if (this._hoverTimeoutId) {
GLib.source_remove(this._hoverTimeoutId);
this._hoverTimeoutId = null;
}
if (!this._panelVisible) {
this._showPanel();
}
return Clutter.EVENT_PROPAGATE;
});
// Click/touch handler for indicator button
connectClickHandler(this, () => {
// Cancel any pending hide timeout
if (this._hoverTimeoutId) {
GLib.source_remove(this._hoverTimeoutId);
this._hoverTimeoutId = null;
}
if (!this._mainMenuHoverActivate) {
// When hover is disabled, click toggles the panel
if (this._panelVisible) {
this._hidePanel();
} else {
this._showPanel();
}
} else {
// When hover is active, click only opens (hover handles close)
if (!this._panelVisible) {
this._showPanel();
}
}
});
// Disable the default menu
this.menu.actor.hide();
}
_loadApplicationsData() {
this._categories = {};
this._appSystem = Shell.AppSystem.get_default();
// Use Gio.AppInfo.get_all() which reliably returns all desktop apps
let allAppInfos = Gio.AppInfo.get_all();
for (let appInfo of allAppInfos) {
if (!appInfo)
continue;
// Skip apps that shouldn't be displayed
if (typeof appInfo.should_show === 'function' && !appInfo.should_show())
continue;
// Get the app ID
let appId = appInfo.get_id();
if (!appId)
continue;
// Try to get Shell.App for icon support
let app = this._appSystem.lookup_app(appId);
// Get categories (only works on DesktopAppInfo)
let categoriesStr = '';
if (typeof appInfo.get_categories === 'function') {
categoriesStr = appInfo.get_categories() || '';
}
let category = this._getMainCategory(categoriesStr);
if (!this._categories[category])
this._categories[category] = [];
// Store both app and appInfo for flexibility
this._categories[category].push({
app: app,
appInfo: appInfo,
name: appInfo.get_name() || appId,
id: appId,
});
}
// Sort apps in each category
for (let category in this._categories) {
this._categories[category].sort((a, b) =>
a.name.localeCompare(b.name));
}
}
_isLiveSession() {
try {
// Check for live-boot marker directory
let liveDir = Gio.File.new_for_path('/run/live');
if (liveDir.query_exists(null))
return true;
// Check kernel command line for boot=live
let cmdlineFile = Gio.File.new_for_path('/proc/cmdline');
if (cmdlineFile.query_exists(null)) {
let [success, contents] = cmdlineFile.load_contents(null);
if (success) {
let decoder = new TextDecoder('utf-8');
let cmdline = decoder.decode(contents);
if (cmdline.includes('boot=live'))
return true;
}
}
} catch (e) {
log(`Praya: Error detecting live session: ${e.message}`);
}
return false;
}
_loadFavourites() {
try {
let file = Gio.File.new_for_path(FAVOURITES_FILE);
if (file.query_exists(null)) {
let [success, contents] = file.load_contents(null);
if (success) {
let decoder = new TextDecoder('utf-8');
let json = decoder.decode(contents);
this._favourites = JSON.parse(json);
}
} else {
// Create file with default favourites
let terminalOrInstaller = this._isLiveSession()
? 'calamares-install-blankon.desktop'
: 'org.gnome.Ptyxis.desktop';
this._favourites = [
'firefox.desktop',
'org.gnome.Nautilus.desktop',
terminalOrInstaller,
];
this._saveFavourites();
}
} catch (e) {
log(`Praya: Error loading favourites: ${e.message}`);
this._favourites = [];
}
}
_saveFavourites() {
try {
let file = Gio.File.new_for_path(FAVOURITES_FILE);
let parent = file.get_parent();
if (!parent.query_exists(null)) {
parent.make_directory_with_parents(null);
}
let json = JSON.stringify(this._favourites);
let encoder = new TextEncoder();
let contents = encoder.encode(json);
file.replace_contents(contents, null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, null);
} catch (e) {
log(`Praya: Error saving favourites: ${e.message}`);
}
}
_isFavourite(appId) {
return this._favourites.includes(appId);
}
_addFavourite(appId) {
if (!this._favourites.includes(appId)) {
this._favourites.push(appId);
this._saveFavourites();
}
}
_removeFavourite(appId) {
let index = this._favourites.indexOf(appId);
if (index !== -1) {
this._favourites.splice(index, 1);
this._saveFavourites();
}
}
_showContextMenu(appData, sourceActor) {
// Destroy existing context menu
if (this._contextMenu) {
this._contextMenu.destroy();
this._contextMenu = null;
}
// Cancel any pending hide timeout
if (this._hoverTimeoutId) {
GLib.source_remove(this._hoverTimeoutId);
this._hoverTimeoutId = null;
}
let isFav = this._isFavourite(appData.id);
// Create context menu container
this._contextMenu = new St.BoxLayout({
style_class: 'praya-context-menu',
vertical: true,
reactive: true,
track_hover: true,
});
// Add hover handlers to keep panel open while interacting with context menu
this._contextMenu.connect('enter-event', () => {
if (this._hoverTimeoutId) {
GLib.source_remove(this._hoverTimeoutId);
this._hoverTimeoutId = null;
}
// Cancel context menu close timeout
if (this._contextMenuTimeoutId) {
GLib.source_remove(this._contextMenuTimeoutId);
this._contextMenuTimeoutId = null;
}
return Clutter.EVENT_PROPAGATE;
});
this._contextMenu.connect('leave-event', () => {
// Close context menu when mouse leaves it
// Use a small delay to allow clicking on items
if (this._contextMenuTimeoutId) {
GLib.source_remove(this._contextMenuTimeoutId);
}
this._contextMenuTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 150, () => {
this._contextMenuTimeoutId = null;
this._closeContextMenu();
return GLib.SOURCE_REMOVE;
});
return Clutter.EVENT_PROPAGATE;
});
// Create menu item
let menuItemText = isFav ? _('Unpin') : _('Pin to Menu');
let menuItemIcon = isFav ? 'view-pin-symbolic' : 'view-pin-symbolic';
let menuItem = new St.BoxLayout({
style_class: 'praya-context-menu-item',
reactive: true,
track_hover: true,
});
let icon = new St.Icon({
icon_name: menuItemIcon,
icon_size: 16,
style_class: 'praya-context-menu-icon',
});
menuItem.add_child(icon);
let label = new St.Label({
text: menuItemText,
y_align: Clutter.ActorAlign.CENTER,
});
menuItem.add_child(label);
connectClickHandler(menuItem, () => {
if (isFav) {
this._removeFavourite(appData.id);
} else {
this._addFavourite(appData.id);
}
this._closeContextMenu();
// Always reset to main menu after pin/unpin
this._navigationStack = [];
this._isSearchActive = false;
if (this._searchEntry) {
this._searchEntry.set_text('');
}
this._showMainMenu(false);
});
this._contextMenu.add_child(menuItem);
// Position the context menu near the source actor
let [x, y] = sourceActor.get_transformed_position();
let [width, height] = sourceActor.get_size();
this._contextMenu.set_position(x + width - 150, y + height / 2);
Main.layoutManager.addTopChrome(this._contextMenu);
// Close context menu when clicking/touching elsewhere
this._contextMenuCaptureId = global.stage.connect('captured-event', (actor, event) => {
if (event.type() === Clutter.EventType.BUTTON_PRESS || event.type() === Clutter.EventType.TOUCH_BEGIN) {
let [eventX, eventY] = event.get_coords();
let dominated = this._contextMenu.contains(global.stage.get_actor_at_pos(Clutter.PickMode.ALL, eventX, eventY));
if (!dominated) {
this._closeContextMenu();
}
}
return Clutter.EVENT_PROPAGATE;
});
}
_closeContextMenu() {
if (this._contextMenuTimeoutId) {
GLib.source_remove(this._contextMenuTimeoutId);
this._contextMenuTimeoutId = null;
}
if (this._contextMenuCaptureId) {
global.stage.disconnect(this._contextMenuCaptureId);
this._contextMenuCaptureId = null;
}
if (this._contextMenu) {
Main.layoutManager.removeChrome(this._contextMenu);
this._contextMenu.destroy();
this._contextMenu = null;
}
}
_getFavouriteApps() {
let favouriteApps = [];
for (let appId of this._favourites) {
let appInfo = GioUnix.DesktopAppInfo.new(appId);
if (appInfo) {
let app = this._appSystem.lookup_app(appId);
favouriteApps.push({
app: app,
appInfo: appInfo,
name: appInfo.get_name() || appId,
id: appId,
});
}
}
return favouriteApps;
}
_getMainCategory(categoriesStr) {
let categories = categoriesStr.split(';');
const mainCategories = [
'AudioVideo', 'Audio', 'Video', 'Development', 'Education',
'Game', 'Graphics', 'Network', 'Office', 'Science', 'Settings',
'System', 'Utility'
];
for (let cat of categories) {
if (mainCategories.includes(cat))
return cat;
}
return 'Other';
}
_togglePanel() {
if (this._panelVisible) {
this._hidePanel();
} else {
this._showPanel();
}
}
_showPanel() {
// Prevent overlapping show/hide transitions
if (this._isPanelTransitioning) return;
this._isPanelTransitioning = true;
// Clean up any existing hover zone first to prevent orphaned zones
if (this._hoverZone) {
try {
Main.layoutManager.removeChrome(this._hoverZone);
} catch (e) {
// Ignore if already removed
}
this._hoverZone.destroy();
this._hoverZone = null;
}
if (this._panel) {
try {
Main.layoutManager.removeChrome(this._panel);
} catch (e) {
// Ignore if already removed
}
this._panel.destroy();
this._panel = null;
}
// Clean up existing menu button hover area
this._removeMenuButtonHoverArea();
// Use the monitor where the pointer currently is (where user clicked the indicator)
this._currentMonitor = Main.layoutManager.currentMonitor;
let monitor = this._currentMonitor;
let panelHeight = Main.panel.height;
let isBottomBar = this._servicesConfig.panelPosition === 'bottom';
let bottomMargin = isBottomBar ? MARGIN_BOTTOM_BAR : MARGIN_BOTTOM;
let availableHeight = monitor.height - panelHeight - MARGIN_TOP - bottomMargin;
let effectiveWidth = this._getEffectivePanelWidth();
// Create invisible hover zone that includes margins
// Position relative to the current monitor's coordinates
let hoverZoneY = isBottomBar ? monitor.y : monitor.y + panelHeight;
this._hoverZone = new St.Widget({
reactive: true,
track_hover: true,
x: monitor.x,
y: hoverZoneY,
width: effectiveWidth + MARGIN_LEFT * 2,
height: availableHeight + MARGIN_TOP + bottomMargin,
});
// Create the main panel container - position depends on bar location
// Position relative to the current monitor's coordinates
let panelY = isBottomBar ? monitor.y + MARGIN_TOP : monitor.y + panelHeight + MARGIN_TOP;
this._panel = new St.BoxLayout({
style_class: 'praya-panel',
vertical: true,
reactive: true,
track_hover: true,
x: monitor.x + MARGIN_LEFT,
y: panelY,
width: effectiveWidth,
height: availableHeight,
});
// Create header (will be populated by _showMainMenu -> _updateHeader)
this._header = new St.BoxLayout({
style_class: 'praya-panel-header',
height: HEADER_HEIGHT,
x_expand: true,
});
this._panel.add_child(this._header);
// Create persistent bottom section first to measure its height
this._bottomSection = this._createBottomSection();
// Base height for bottom section when collapsed (User ~72 + Lock 52 + LogOut 52 + Power 52 + separator ~17 + padding)
this._bottomSectionBaseHeight = 260;
// Additional height when power menu is expanded
this._powerOptionsHeight = 150;
// Create sliding container for navigation with clipping
this._slidingContainer = new St.Widget({
style_class: 'praya-sliding-container',
x_expand: true,
clip_to_allocation: true,
});
this._slidingContainer.set_size(effectiveWidth, availableHeight - HEADER_HEIGHT - this._bottomSectionBaseHeight);
this._panel.add_child(this._slidingContainer);
this._panel.add_child(this._bottomSection);
// Check if we should restore chatbot mode
if (this._isChatbotMode) {
// Restore chatbot mode
this._restoreChatbotMode();
} else {
// Show main menu
this._navigationStack = [];
this._showMainMenu(false);
}
// Start with opacity 0 and off-screen to the left for slide-in animation
this._panel.opacity = 0;
this._panel.x = monitor.x + MARGIN_LEFT - effectiveWidth;
Main.layoutManager.addTopChrome(this._hoverZone);
Main.layoutManager.addTopChrome(this._panel);
this._panelVisible = true;
// Fade in + slide to right animation
let targetWidth = this._isChatbotMode ? CHATBOT_PANEL_WIDTH : effectiveWidth;
this._panel.ease({
opacity: 255,
x: monitor.x + MARGIN_LEFT,
duration: 200,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => {
this._isPanelTransitioning = false;
// Grab keyboard focus
if (this._isChatbotMode && this._chatbotPanel) {
this._chatbotPanel.focusInput();
} else if (this._searchEntry) {
this._searchEntry.grab_key_focus();
}
}
});
// Add key capture for navigation and search
this._keyPressId = global.stage.connect('key-press-event', (actor, event) => {
if (!this._panelVisible)
return Clutter.EVENT_PROPAGATE;
let keyval = event.get_key_symbol();
let keychar = String.fromCharCode(Clutter.keysym_to_unicode(keyval));
// Handle arrow key navigation
if (keyval === Clutter.KEY_Down) {
this._navigateMenu(1);
return Clutter.EVENT_STOP;
} else if (keyval === Clutter.KEY_Up) {
this._navigateMenu(-1);
return Clutter.EVENT_STOP;
} else if (keyval === Clutter.KEY_Return || keyval === Clutter.KEY_KP_Enter) {
// If search entry has focus and has text, launch first result
if (this._searchEntry && this._searchEntry.has_key_focus() && this._searchEntry.get_text().trim() !== '') {
this._launchFirstSearchResult();
return Clutter.EVENT_STOP;
}
// Otherwise activate focused menu item
if (this._focusedIndex >= 0 && this._focusedIndex < this._menuItems.length) {
this._activateMenuItem(this._focusedIndex);
return Clutter.EVENT_STOP;
}
} else if (keyval === Clutter.KEY_Right) {
// Enter submenu if focused item has children
if (this._focusedIndex >= 0 && this._focusedIndex < this._menuItems.length) {
let item = this._menuItems[this._focusedIndex];
if (item._hasChildren) {
this._activateMenuItem(this._focusedIndex);
return Clutter.EVENT_STOP;
}
}
} else if (keyval === Clutter.KEY_Left || keyval === Clutter.KEY_BackSpace) {
// Go back if in nested menu (but not if typing in search)
if (this._navigationStack.length > 0) {
if (keyval === Clutter.KEY_BackSpace && this._searchEntry && this._searchEntry.has_key_focus()) {
return Clutter.EVENT_PROPAGATE;
}
if (!this._isAnimating) this._goBack();
return Clutter.EVENT_STOP;
}
}
// Check if it's an alphanumeric character
if (/^[a-zA-Z0-9]$/.test(keychar)) {
// If we're in a nested menu (no search entry), go back to main first
if (!this._searchEntry || this._navigationStack.length > 0) {
this._navigationStack = [];
this._isSearchActive = false;
this._showMainMenu(false);
}
// Now we should have a search entry
if (this._searchEntry) {
// Check if search entry already has focus
if (!this._searchEntry.has_key_focus()) {
this._searchEntry.grab_key_focus();
// Insert the character into the search entry
this._searchEntry.set_text(keychar);
// Move cursor to end
this._searchEntry.clutter_text.set_cursor_position(-1);
}
}
return Clutter.EVENT_STOP;
}
return Clutter.EVENT_PROPAGATE;
});
// Add hover handler on the panel to keep it open
this._panelEnterId = this._panel.connect('enter-event', () => {
if (this._hoverTimeoutId) {
GLib.source_remove(this._hoverTimeoutId);
this._hoverTimeoutId = null;
}
return Clutter.EVENT_PROPAGATE;
});
this._panelLeaveId = this._panel.connect('leave-event', () => {
if (this._mainMenuHoverActivate) {
this._scheduleHidePanel();
}
return Clutter.EVENT_PROPAGATE;
});
// Add hover handler on the hover zone (includes margins)
this._hoverZoneEnterId = this._hoverZone.connect('enter-event', () => {
if (this._hoverTimeoutId) {
GLib.source_remove(this._hoverTimeoutId);
this._hoverTimeoutId = null;
}
return Clutter.EVENT_PROPAGATE;
});
this._hoverZoneLeaveId = this._hoverZone.connect('leave-event', () => {
if (this._mainMenuHoverActivate) {
this._scheduleHidePanel();
}
return Clutter.EVENT_PROPAGATE;
});
// Also handle leaving the indicator button
this._indicatorLeaveId = this.connect('leave-event', () => {
if (this._mainMenuHoverActivate) {
this._scheduleHidePanel();
}
return Clutter.EVENT_PROPAGATE;
});
// Add click/touch-outside handler for stage (desktop background)
this._captureEventId = global.stage.connect('captured-event', (actor, event) => {
if (event.type() === Clutter.EventType.BUTTON_PRESS || event.type() === Clutter.EventType.TOUCH_BEGIN) {
let [x, y] = event.get_coords();
// Check if click is on the indicator button or menu button hover area (don't hide)
let clickedActor = global.stage.get_actor_at_pos(Clutter.PickMode.ALL, x, y);
let dominated = this.contains(clickedActor);
if (dominated) {
return Clutter.EVENT_PROPAGATE;
}
if (this._menuButtonHoverArea && (this._menuButtonHoverArea === clickedActor || this._menuButtonHoverArea.contains(clickedActor))) {
return Clutter.EVENT_PROPAGATE;
}
// Check if click is outside the panel (with margins)
// Use actual panel width to handle chatbot mode (400px) vs normal mode (325px)
// Account for monitor offset for multi-monitor setups
let monitor = this._currentMonitor;
let currentPanelWidth = this._panel ? this._panel.width : PANEL_WIDTH;
let panelLeft = monitor.x + MARGIN_LEFT;
let panelRight = panelLeft + currentPanelWidth;
let isBottomBar = this._servicesConfig.panelPosition === 'bottom';
let panelTop = isBottomBar ? monitor.y + MARGIN_TOP : monitor.y + Main.panel.height + MARGIN_TOP;
let panelBottom = panelTop + this._panel.height;
if (x < panelLeft || x > panelRight || y < panelTop || y > panelBottom) {
this._hidePanel();
return Clutter.EVENT_STOP;
}
}
return Clutter.EVENT_PROPAGATE;
});
// Add focus change handler to close when clicking on windows
this._focusWindowId = global.display.connect('notify::focus-window', () => {
// Only hide if a window gets focus (user clicked on a window)
// Don't hide just because our panel got focus
if (this._panelVisible && global.display.focus_window) {
// Small delay to allow our panel to process focus first
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 50, () => {
if (this._panelVisible && global.display.focus_window) {
this._hidePanel();
}
return GLib.SOURCE_REMOVE;
});
}
});
// Create the menu button hover area
this._setupMenuButtonHoverArea();
}
_setupMenuButtonHoverArea() {
let monitor = this._currentMonitor || Main.layoutManager.primaryMonitor;
if (!monitor) return;
let isBottomBar = this._servicesConfig.panelPosition === 'bottom';
let triggerX = monitor.x;
let triggerY = isBottomBar
? monitor.y + monitor.height - 25
: monitor.y;
this._menuButtonHoverArea = new St.Widget({
reactive: true,
track_hover: true,
x: triggerX,
y: triggerY,
width: 95,
height: 25,
style: 'background-color: transparent;',
});
connectClickHandler(this._menuButtonHoverArea, () => {
if (this._panelVisible) {
this._hidePanel();
} else {
this._showPanel();
}
});
// Hover behavior same as indicator button
this._menuButtonHoverArea.connect('enter-event', () => {
if (!this._mainMenuHoverActivate) return Clutter.EVENT_PROPAGATE;
if (this._hoverTimeoutId) {
GLib.source_remove(this._hoverTimeoutId);
this._hoverTimeoutId = null;
}
if (!this._panelVisible) {
this._showPanel();
}
return Clutter.EVENT_PROPAGATE;
});
this._menuButtonHoverArea.connect('leave-event', () => {
if (this._mainMenuHoverActivate) {
this._scheduleHidePanel();
}
return Clutter.EVENT_PROPAGATE;
});
global.stage.add_child(this._menuButtonHoverArea);
}
_removeMenuButtonHoverArea() {
if (this._menuButtonHoverArea) {
if (this._menuButtonHoverArea.get_parent()) {
this._menuButtonHoverArea.get_parent().remove_child(this._menuButtonHoverArea);
}
this._menuButtonHoverArea.destroy();
this._menuButtonHoverArea = null;
}
}
_scheduleHidePanel() {
// Don't schedule hide if context menu is open or transitioning chatbot
if (this._contextMenu || this._isTransitioningChatbot) {
return;
}
if (this._hoverTimeoutId) {
GLib.source_remove(this._hoverTimeoutId);
}
this._hoverTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 150, () => {
this._hoverTimeoutId = null;
// Double-check context menu isn't open and not transitioning when timeout fires
if (!this._contextMenu && !this._isTransitioningChatbot) {
this._hidePanel();
}
return GLib.SOURCE_REMOVE;
});
}
_hidePanel() {
// Prevent overlapping show/hide transitions
if (this._isPanelTransitioning) return;
this._isPanelTransitioning = true;
// Close context menu first
this._closeContextMenu();
// Preserve chatbot messages before destroying panel (keep _isChatbotMode flag)
if (this._chatbotPanel) {
this._chatbotMessages = this._chatbotPanel.getMessages();
this._chatbotPanel.destroy();
this._chatbotPanel = null;
}
if (this._hoverTimeoutId) {
GLib.source_remove(this._hoverTimeoutId);
this._hoverTimeoutId = null;
}
if (this._captureEventId) {
global.stage.disconnect(this._captureEventId);
this._captureEventId = null;
}
if (this._keyPressId) {
global.stage.disconnect(this._keyPressId);
this._keyPressId = null;
}
if (this._focusWindowId) {
global.display.disconnect(this._focusWindowId);
this._focusWindowId = null;
}
if (this._indicatorLeaveId) {
this.disconnect(this._indicatorLeaveId);
this._indicatorLeaveId = null;
}
if (this._panel && this._panelEnterId) {
this._panel.disconnect(this._panelEnterId);
this._panelEnterId = null;
}
if (this._panel && this._panelLeaveId) {
this._panel.disconnect(this._panelLeaveId);
this._panelLeaveId = null;
}
if (this._hoverZone && this._hoverZoneEnterId) {
this._hoverZone.disconnect(this._hoverZoneEnterId);
this._hoverZoneEnterId = null;
}
if (this._hoverZone && this._hoverZoneLeaveId) {
this._hoverZone.disconnect(this._hoverZoneLeaveId);
this._hoverZoneLeaveId = null;
}
this._panelVisible = false;
this._navigationStack = [];
this._isSearchActive = false;
this._isAnimating = false;
this._searchEntry = null;
this._focusedIndex = -1;
this._menuItems = [];
this._menuBox = null;
this._bottomSection = null;
// Remove menu button hover area
this._removeMenuButtonHoverArea();
// Get the monitor offset for animation (use stored monitor or fall back to current)
let monitorX = this._currentMonitor ? this._currentMonitor.x : 0;
// Immediately disable reactivity to prevent blocking clicks during animation
if (this._hoverZone) {
this._hoverZone.reactive = false;
}
if (this._panel) {
this._panel.reactive = false;
}
// Clean up hover zone immediately if panel doesn't exist
if (this._hoverZone && !this._panel) {
Main.layoutManager.removeChrome(this._hoverZone);
this._hoverZone.destroy();
this._hoverZone = null;
}
if (!this._panel) {
this._isPanelTransitioning = false;
return;
}
if (this._panel) {
// Fade out + slide to left animation
this._panel.ease({
opacity: 0,
x: monitorX + MARGIN_LEFT - this._getEffectivePanelWidth(),
duration: 150,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => {
if (this._hoverZone) {
try {
Main.layoutManager.removeChrome(this._hoverZone);
} catch (e) {
// Ignore if already removed
}
this._hoverZone.destroy();
this._hoverZone = null;
}
if (this._panel) {
try {
Main.layoutManager.removeChrome(this._panel);
} catch (e) {
// Ignore if already removed
}
this._panel.destroy();
this._panel = null;
}
// Clear the stored monitor reference
this._currentMonitor = null;
this._isPanelTransitioning = false;
}
});
}
}
_createScrollView(height = null) {
let scrollView = new St.ScrollView({
style_class: 'praya-scroll',
hscrollbar_policy: St.PolicyType.NEVER,
vscrollbar_policy: St.PolicyType.AUTOMATIC,
x_expand: true,
y_expand: true,
});
// Use sliding container height which already accounts for bottom section
let containerHeight = this._slidingContainer ? this._slidingContainer.height : 400;
scrollView.set_size(this._getEffectivePanelWidth(), height || containerHeight);
return scrollView;
}
_navigateMenu(direction) {
if (this._menuItems.length === 0)
return;
// Remove focus from search entry if navigating
if (this._searchEntry && this._searchEntry.has_key_focus()) {
global.stage.set_key_focus(null);
}
let newIndex = this._focusedIndex + direction;
// Wrap around
if (newIndex < 0)
newIndex = this._menuItems.length - 1;
else if (newIndex >= this._menuItems.length)
newIndex = 0;
this._setFocusedIndex(newIndex);
}
_setFocusedIndex(index) {
// Remove highlight from previous item
if (this._focusedIndex >= 0 && this._focusedIndex < this._menuItems.length) {
this._menuItems[this._focusedIndex].remove_style_class_name('praya-menu-item-focused');
}
this._focusedIndex = index;