Files
clapper/clapper_src/app.js
Rafostar ff58713426 Add "Floating Window Mode"
A simple borderless window floating on desktop. Window can be resized and moved by dragging. It also has some minimalistic controls showing on top of the video when cursor is hovering over it.\n\n This was a feature originally requested by @zahid1905.
2020-11-03 17:40:19 +01:00

101 lines
2.5 KiB
JavaScript

const { Gio, GObject, Gtk } = imports.gi;
const { HeaderBar } = imports.clapper_src.headerbar;
const { Widget } = imports.clapper_src.widget;
const Debug = imports.clapper_src.debug;
const Menu = imports.clapper_src.menu;
const Misc = imports.clapper_src.misc;
let { debug } = Debug;
const APP_NAME = 'Clapper';
const APP_ID = 'com.github.rafostar.Clapper';
var App = GObject.registerClass(
class ClapperApp extends Gtk.Application
{
_init(opts)
{
super._init({
application_id: APP_ID
});
let defaults = {
playlist: [],
};
Object.assign(this, defaults, opts);
}
vfunc_startup()
{
super.vfunc_startup();
let window = new Gtk.ApplicationWindow({
application: this,
title: APP_NAME,
});
for(let action of Menu.actions) {
let simpleAction = new Gio.SimpleAction({
name: action.name
});
simpleAction.connect('activate', () =>
action(this.active_window, APP_NAME)
);
this.add_action(simpleAction);
}
let clapperWidget = new Widget();
window.set_child(clapperWidget);
let size = clapperWidget.player.settings.get_string('window-size');
try {
size = JSON.parse(size);
}
catch(err) {
debug(err);
size = null;
}
if(size) {
window.set_default_size(size[0], size[1]);
debug(`restored window dimensions: ${size[0]}x${size[1]}`);
}
let clapperPath = Misc.getClapperPath();
let uiBuilder = Gtk.Builder.new_from_file(
`${clapperPath}/ui/clapper.ui`
);
let models = {
addMediaMenu: uiBuilder.get_object('addMediaMenu'),
settingsMenu: uiBuilder.get_object('settingsMenu'),
};
let headerBar = new HeaderBar(window, models);
window.set_titlebar(headerBar);
}
vfunc_activate()
{
super.vfunc_activate();
this.windowShowSignal = this.active_window.connect(
'show', this._onWindowShow.bind(this)
);
this.active_window.present();
}
run(arr)
{
super.run(arr || []);
}
_onWindowShow(window)
{
window.disconnect(this.windowShowSignal);
this.windowShowSignal = null;
if(this.playlist.length) {
let { player } = window.get_child();
player.set_playlist(this.playlist);
}
}
});