Add toggle fullscreen button

This commit is contained in:
Rafostar
2020-08-31 22:21:46 +02:00
parent 918ba34885
commit f70fe43303
3 changed files with 44 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
const { GLib, GObject, Gtk } = imports.gi;
const { Gdk, GLib, GObject, Gtk } = imports.gi;
const { Player } = imports.clapper_src.player;
const { Interface } = imports.clapper_src.interface;
@@ -18,6 +18,7 @@ var App = GObject.registerClass({
super._init();
this.isFullscreen = false;
this.connect('startup', () => this._buildUI());
this.connect('activate', () => this._openDialog());
}
@@ -28,6 +29,12 @@ var App = GObject.registerClass({
super.run(arr);
}
toggleFullscreen()
{
let isUn = (this.isFullscreen) ? 'un' : '';
this.appWindow[`${isUn}fullscreen`]();
}
_buildUI()
{
this.appWindow = new Gtk.ApplicationWindow({
@@ -39,13 +46,24 @@ var App = GObject.registerClass({
width_request: 960,
height_request: 642
});
this.appWindow.connect(
'window-state-event', this._onWindowStateEvent.bind(this)
);
this.interface = new Interface();
this.interface.controls.toggleFullscreenButton.connect(
'clicked', this.toggleFullscreen.bind(this)
);
this.appWindow.add(this.interface);
this.appWindow.connect('realize', this._onRealize.bind(this));
}
_openDialog()
{
this.appWindow.show_all();
}
_onRealize()
{
this.player = new Player();
@@ -55,8 +73,17 @@ var App = GObject.registerClass({
this.emit('player-ready', true);
}
_openDialog()
_onWindowStateEvent(widget, event)
{
this.appWindow.show_all();
let window = event.get_window();
let state = window.get_state();
this.isFullscreen = Boolean(state & Gdk.WindowState.FULLSCREEN);
this.interface.controls.toggleFullscreenButton.image = (this.isFullscreen)
? this.interface.controls.unfullscreenImage
: this.interface.controls.fullscreenImage;
let action = (this.isFullscreen) ? 'hide' : 'show';
this.interface.controls[action]();
}
});