75 lines
2.9 KiB
JavaScript
75 lines
2.9 KiB
JavaScript
import Meta from 'gi://Meta';
|
|
import St from 'gi://St';
|
|
|
|
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
|
|
|
import {CalendarPanel} from './calendar.js';
|
|
import {NotesPanel} from './notes.js';
|
|
import {Store} from './store.js';
|
|
import {Sync} from './sync.js';
|
|
import {TodoPanel} from './todos.js';
|
|
|
|
// Die eigentliche Extension. extension.js lädt dieses Modul bei jedem Einschalten frisch,
|
|
// der Zustand liegt auf dem Extension-Objekt (ext), damit Tests und D-Bus ihn dort finden.
|
|
|
|
const MARGIN = 24;
|
|
|
|
export function enable(ext) {
|
|
ext._store = new Store();
|
|
|
|
// Nur die Panels sind reaktiv. Der Rest lässt Klicks zum Desktop durch.
|
|
ext._root = new St.BoxLayout({style_class: 'desktop-root', reactive: false});
|
|
ext._notes = new NotesPanel(ext._store);
|
|
ext._root.add_child(ext._notes);
|
|
// Rechte Spalte füllt den Rest, der Abstand dazwischen entspricht dem Außenrand.
|
|
const right = new St.BoxLayout({vertical: true, style_class: 'desktop-right', reactive: false, x_expand: true});
|
|
right.add_child(new CalendarPanel(ext._store));
|
|
right.add_child(new TodoPanel(ext._store));
|
|
ext._root.add_child(right);
|
|
|
|
global.window_group.add_child(ext._root);
|
|
ext._restackId = global.display.connect('restacked', () => restack(ext));
|
|
ext._mapId = global.window_manager.connect('map', () => restack(ext));
|
|
ext._workareaId = global.display.connect('workareas-changed', () => layout(ext));
|
|
layout(ext);
|
|
restack(ext);
|
|
|
|
ext._sync = new Sync(ext._store);
|
|
ext._sync.start();
|
|
}
|
|
|
|
export function disable(ext) {
|
|
ext._sync.stop();
|
|
ext._sync = null;
|
|
global.display.disconnect(ext._restackId);
|
|
global.window_manager.disconnect(ext._mapId);
|
|
global.display.disconnect(ext._workareaId);
|
|
ext._root.destroy();
|
|
ext._root = null;
|
|
ext._notes = null;
|
|
ext._store = null;
|
|
}
|
|
|
|
// Füllt den Arbeitsbereich des Hauptmonitors (ohne Topbar und Dock). Notizen nehmen die halbe Bildschirmbreite.
|
|
function layout(ext) {
|
|
const area = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
|
|
ext._root.set_position(area.x + MARGIN, area.y + MARGIN);
|
|
ext._root.set_size(area.width - 2 * MARGIN, area.height - 2 * MARGIN);
|
|
ext._notes.set_width(Math.round(Main.layoutManager.primaryMonitor.width / 2));
|
|
}
|
|
|
|
// Liegt direkt über Desktop-Fenstern (z.B. Desktop Icons), sonst direkt über dem Wallpaper.
|
|
// Mutter sortiert die Fensterebene bei jedem Restack neu, daher hier nachziehen.
|
|
function restack(ext) {
|
|
let below = Main.layoutManager._backgroundGroup;
|
|
for (const actor of global.window_group.get_children()) {
|
|
if (!(actor instanceof Meta.WindowActor))
|
|
continue;
|
|
const window = actor.meta_window;
|
|
const isDing = window.customJS_ding || window.title?.startsWith('Desktop Icons');
|
|
if (isDing || window.window_type === Meta.WindowType.DESKTOP)
|
|
below = actor;
|
|
}
|
|
global.window_group.set_child_above_sibling(ext._root, below);
|
|
}
|