Fix enter fullscreen and popover buttons

This commit is contained in:
Rafostar
2020-10-07 16:40:42 +02:00
parent dbdb6988a2
commit 041b31c161
6 changed files with 138 additions and 201 deletions

View File

@@ -21,8 +21,6 @@ var App = GObject.registerClass({
{ {
_init(opts) _init(opts)
{ {
GLib.set_prgname(APP_NAME);
super._init({ super._init({
application_id: pkg.name application_id: pkg.name
}); });
@@ -204,27 +202,15 @@ var App = GObject.registerClass({
_onWindowFullscreenChanged(window, isFullscreen) _onWindowFullscreenChanged(window, isFullscreen)
{ {
// when changing fullscreen pango layout of popup is lost
// and we need to re-add marks to the new layout
this.interface.controls.setVolumeMarks(false);
if(isFullscreen) { if(isFullscreen) {
this.setUpdateTimeInterval(); this.setUpdateTimeInterval();
this.setHideControlsTimeout(); this.setHideControlsTimeout();
this.interface.controls.unfullscreenButton.set_sensitive(true);
this.interface.controls.unfullscreenButton.show();
this.interface.showControls(true);
} }
else { else {
this.clearTimeout('updateTime'); this.clearTimeout('updateTime');
this.interface.controls.unfullscreenButton.set_sensitive(false);
this.interface.controls.unfullscreenButton.hide();
this.interface.showControls(false);
} }
this.interface.setControlsOnVideo(isFullscreen); this.interface.setFullscreenMode(isFullscreen);
this.interface.controls.setVolumeMarks(true);
this.interface.controls.setFullscreenMode(isFullscreen);
} }
_onWindowKeyPressEvent(self, event) _onWindowKeyPressEvent(self, event)

View File

@@ -1,41 +1,51 @@
const { GObject, Gtk } = imports.gi; const { GObject, Gtk } = imports.gi;
var BoxedIconButton = GObject.registerClass( var IconButton = GObject.registerClass(
class BoxedIconButton extends Gtk.Button class ClapperIconButton extends Gtk.Button
{ {
_init(icon, size, isFullscreen) _init(icon)
{ {
super._init({ super._init({
margin_top: 4, margin_top: 4,
margin_bottom: 4, margin_bottom: 4,
margin_start: 1,
margin_end: 1,
can_focus: false, can_focus: false,
//can_default: false, icon_name: icon,
}); });
this.isFullscreen = isFullscreen || false; this.isFullscreen = false;
size = size || Gtk.IconSize.SMALL_TOOLBAR;
let image = Gtk.Image.new_from_icon_name(icon);
//if(image)
//this.set_image(image);
/*
this.image.defaultSize = size;
this.image.fullscreenSize = (size === Gtk.IconSize.SMALL_TOOLBAR)
? Gtk.IconSize.LARGE_TOOLBAR
: Gtk.IconSize.DND;
*/
this.add_css_class('flat'); this.add_css_class('flat');
this.box = new Gtk.Box();
this.box.append(this);
super.show();
} }
get visible() setFullscreenMode(isFullscreen)
{ {
return this.box.visible; this.isFullscreen = isFullscreen;
}
});
var PopoverButton = GObject.registerClass(
class ClapperPopoverButton extends IconButton
{
_init(icon)
{
super._init(icon);
this.popover = new Gtk.Popover({
position: Gtk.PositionType.TOP,
});
this.popoverBox = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
});
this.popover.set_parent(this);
this.popover.set_child(this.popoverBox);
this.popover.set_offset(0, -this.margin_top);
if(this.isFullscreen)
this.popover.add_css_class('osd');
this.destroySignal = this.connect('destroy', this._onDestroy.bind(this));
} }
setFullscreenMode(isFullscreen) setFullscreenMode(isFullscreen)
@@ -43,62 +53,30 @@ class BoxedIconButton extends Gtk.Button
if(this.isFullscreen === isFullscreen) if(this.isFullscreen === isFullscreen)
return; return;
this.image.icon_size = (isFullscreen) this.margin_top = (isFullscreen) ? 6 : 4;
? this.image.fullscreenSize this.popover.set_offset(0, -this.margin_top);
: this.image.defaultSize;
this.isFullscreen = isFullscreen; let cssClass = 'osd';
} if(isFullscreen == this.popover.has_css_class(cssClass))
/*
show_all()
{
this.box.show_all();
}
*/
show()
{
this.box.show();
}
hide()
{
this.box.hide();
}
});
var BoxedPopoverButton = GObject.registerClass(
class BoxedPopoverButton extends BoxedIconButton
{
_init(icon, size, isFullscreen)
{
super._init(icon, size, isFullscreen);
this.popover = new Gtk.Popover({
default_widget: this.box
});
this.popoverBox = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL
});
this.popover.set_child(this.popoverBox);
this.popoverBox.show();
if(this.isFullscreen)
this.popover.add_css_class('osd');
}
setFullscreenMode(isEnabled)
{
if(this.isFullscreen === isEnabled)
return; return;
let action = (isEnabled) ? 'add' : 'remove'; let action = (isFullscreen) ? 'add' : 'remove';
this.popover[action + '_css_class']('osd'); this.popover[action + '_css_class'](cssClass);
super.setFullscreenMode(isEnabled); super.setFullscreenMode(isFullscreen);
} }
vfunc_clicked() vfunc_clicked()
{ {
this.popover.popup(); this.popover.popup();
} }
_onDestroy()
{
this.disconnect(this.destroySignal);
this.popover.unparent();
this.popoverBox.emit('destroy');
this.popover.emit('destroy');
}
}); });

View File

@@ -31,7 +31,6 @@ var Controls = GObject.registerClass({
valign: Gtk.Align.END, valign: Gtk.Align.END,
}); });
this.fullscreenMode = false;
this.durationFormated = '00:00:00'; this.durationFormated = '00:00:00';
this.buttonsArr = []; this.buttonsArr = [];
@@ -52,124 +51,100 @@ var Controls = GObject.registerClass({
this._addVolumeButton(); this._addVolumeButton();
this.unfullscreenButton = this.addButton( this.unfullscreenButton = this.addButton(
'view-restore-symbolic', 'view-restore-symbolic',
Gtk.IconSize.SMALL_TOOLBAR,
true
); );
this.unfullscreenButton.set_visible(false);
this.fullscreenButton = Gtk.Button.new_from_icon_name( this.fullscreenButton = Gtk.Button.new_from_icon_name(
'view-fullscreen-symbolic', 'view-fullscreen-symbolic',
//Gtk.IconSize.SMALL_TOOLBAR
); );
this.setDefaultWidgetBehaviour(this.fullscreenButton); this.setDefaultWidgetBehaviour(this.fullscreenButton);
this.openMenuButton = Gtk.Button.new_from_icon_name( this.openMenuButton = Gtk.Button.new_from_icon_name(
'open-menu-symbolic', 'open-menu-symbolic',
//Gtk.IconSize.SMALL_TOOLBAR
); );
this.setDefaultWidgetBehaviour(this.openMenuButton); this.setDefaultWidgetBehaviour(this.openMenuButton);
//this.forall(this.setDefaultWidgetBehaviour); //this.forall(this.setDefaultWidgetBehaviour);
this.realizeSignal = this.connect('realize', this._onControlsRealize.bind(this)); this.realizeSignal = this.connect('realize', this._onRealize.bind(this));
this.destroySignal = this.connect('destroy', this._onControlsDestroy.bind(this)); this.destroySignal = this.connect('destroy', this._onDestroy.bind(this));
}
pack_start(widget, expand, fill, padding)
{
if(
widget.box
&& widget.box.constructor
&& widget.box.constructor === Gtk.Box
)
widget = widget.box;
super.append(widget);
} }
setFullscreenMode(isFullscreen) setFullscreenMode(isFullscreen)
{ {
if(isFullscreen === this.fullscreenMode)
return;
for(let button of this.buttonsArr) for(let button of this.buttonsArr)
button.setFullscreenMode(isFullscreen); button.setFullscreenMode(isFullscreen);
this.fullscreenMode = isFullscreen; this.unfullscreenButton.set_visible(isFullscreen);
} }
addButton(iconName, size, noPack) addButton(iconName)
{ {
let button = new Buttons.BoxedIconButton( let button = new Buttons.IconButton(iconName);
iconName, size, this.fullscreenMode this.append(button);
);
if(!noPack)
this.pack_start(button, false, false, 0);
this.buttonsArr.push(button);
return button;
}
addPopoverButton(iconName, size)
{
let button = new Buttons.BoxedPopoverButton(
iconName, size, this.fullscreenMode
);
this.pack_start(button, false, false, 0);
this.buttonsArr.push(button); this.buttonsArr.push(button);
return button; return button;
} }
addRadioButtons(box, array, activeId) addPopoverButton(iconName)
{ {
return; let button = new Buttons.PopoverButton(iconName);
this.append(button);
this.buttonsArr.push(button);
return button;
}
addCheckButtons(box, array, activeId)
{
let group = null; let group = null;
let children = box.get_children(); let child = box.get_first_child();
let lastEl = (children.length > array.length) let i = 0;
? children.length
: array.length;
for(let i = 0; i < lastEl; i++) { while(child || i < array.length) {
if(i >= array.length) { if(i >= array.length) {
children[i].hide(); child.hide();
debug(`hiding unused ${children[i].type} radioButton nr: ${i}`); debug(`hiding unused ${child.type} checkButton nr: ${i}`);
i++;
child = child.get_next_sibling();
continue; continue;
} }
let el = array[i]; let el = array[i];
let radioButton; let checkButton;
if(i < children.length) { if(child) {
radioButton = children[i]; checkButton = child;
debug(`reusing ${el.type} radioButton nr: ${i}`); debug(`reusing ${el.type} checkButton nr: ${i}`);
} }
else { else {
debug(`creating new ${el.type} radioButton nr: ${i}`); debug(`creating new ${el.type} checkButton nr: ${i}`);
radioButton = new Gtk.RadioButton({ checkButton = new Gtk.CheckButton({
group: group, group: group,
}); });
radioButton.connect( checkButton.connect(
'toggled', 'toggled',
this._onRadioButtonToggled.bind(this, radioButton) this._onCheckButtonToggled.bind(this, checkButton)
); );
this.setDefaultWidgetBehaviour(radioButton); this.setDefaultWidgetBehaviour(checkButton);
box.add(radioButton); box.append(checkButton);
} }
radioButton.label = el.label; checkButton.label = el.label;
debug(`radioButton label: ${radioButton.label}`); debug(`checkButton label: ${checkButton.label}`);
radioButton.type = el.type; checkButton.type = el.type;
debug(`radioButton type: ${radioButton.type}`); debug(`checkButton type: ${checkButton.type}`);
radioButton.activeId = el.activeId; checkButton.activeId = el.activeId;
debug(`radioButton id: ${radioButton.activeId}`); debug(`checkButton id: ${checkButton.activeId}`);
if(radioButton.activeId === activeId) { if(checkButton.activeId === activeId) {
radioButton.set_active(true); checkButton.set_active(true);
debug(`activated ${el.type} radioButton nr: ${i}`); debug(`activated ${el.type} checkButton nr: ${i}`);
} }
if(!group) if(!group)
group = radioButton; group = checkButton;
radioButton.show(); i++;
if(child)
child = child.get_next_sibling();
} }
} }
@@ -179,16 +154,6 @@ var Controls = GObject.registerClass({
//widget.can_default = false; //widget.can_default = false;
} }
setVolumeMarks(isAdded)
{
if(!isAdded)
return this.volumeScale.clear_marks();
this.volumeScale.add_mark(0, Gtk.PositionType.LEFT, '0%');
this.volumeScale.add_mark(1, Gtk.PositionType.LEFT, '100%');
this.volumeScale.add_mark(2, Gtk.PositionType.LEFT, '200%');
}
handleScaleIncrement(type, isUp) handleScaleIncrement(type, isUp)
{ {
let value = this[`${type}Scale`].get_value(); let value = this[`${type}Scale`].get_value();
@@ -252,7 +217,7 @@ var Controls = GObject.registerClass({
); );
*/ */
this.positionAdjustment = this.positionScale.get_adjustment(); this.positionAdjustment = this.positionScale.get_adjustment();
this.pack_start(this.positionScale, true, true, 0); this.append(this.positionScale);
} }
_addVolumeButton() _addVolumeButton()
@@ -280,10 +245,11 @@ var Controls = GObject.registerClass({
this.volumeAdjustment.set_page_increment(0.05); this.volumeAdjustment.set_page_increment(0.05);
this.setDefaultWidgetBehaviour(this.volumeScale); this.setDefaultWidgetBehaviour(this.volumeScale);
for(let i = 0; i <= 2; i++) {
let text = (i) ? `${i}00%` : '0%';
this.volumeScale.add_mark(i, Gtk.PositionType.LEFT, text);
}
this.volumeButton.popoverBox.append(this.volumeScale); this.volumeButton.popoverBox.append(this.volumeScale);
//this.volumeButton.popoverBox.show_all();
this.setVolumeMarks(true);
} }
_getFormatedTime(time) _getFormatedTime(time)
@@ -297,25 +263,25 @@ var Controls = GObject.registerClass({
return `${hours}:${minutes}:${seconds}`; return `${hours}:${minutes}:${seconds}`;
} }
_onRadioButtonToggled(self, radioButton) _onCheckButtonToggled(self, checkButton)
{ {
if(!radioButton.get_active()) if(!checkButton.get_active())
return; return;
switch(radioButton.type) { switch(checkButton.type) {
case 'video': case 'video':
case 'audio': case 'audio':
case 'subtitle': case 'subtitle':
this.emit( this.emit(
'track-change-requested', 'track-change-requested',
radioButton.type, checkButton.type,
radioButton.activeId checkButton.activeId
); );
break; break;
case 'visualization': case 'visualization':
this.emit( this.emit(
`${radioButton.type}-change-requested`, `${checkButton.type}-change-requested`,
radioButton.activeId checkButton.activeId
); );
break; break;
default: default:
@@ -341,7 +307,7 @@ var Controls = GObject.registerClass({
this.emit('position-seeking-changed', this.isPositionSeeking); this.emit('position-seeking-changed', this.isPositionSeeking);
} }
_onControlsRealize() _onRealize()
{ {
this.disconnect(this.realizeSignal); this.disconnect(this.realizeSignal);
@@ -380,9 +346,15 @@ var Controls = GObject.registerClass({
} }
} }
_onControlsDestroy() _onDestroy()
{ {
this.disconnect(this.destroySignal); this.disconnect(this.destroySignal);
this.positionScale.set_format_value_func(null); this.positionScale.set_format_value_func(null);
this.visualizationsButton.emit('destroy');
this.videoTracksButton.emit('destroy');
this.audioTracksButton.emit('destroy');
this.subtitleTracksButton.emit('destroy');
this.volumeButton.emit('destroy');
} }
}); });

View File

@@ -19,7 +19,7 @@ class ClapperInterface extends Gtk.Grid
}; };
Object.assign(this, defaults, opts); Object.assign(this, defaults, opts);
this.controlsInVideo = false; this.fullscreenMode = false;
this.lastVolumeValue = null; this.lastVolumeValue = null;
this.lastPositionValue = 0; this.lastPositionValue = 0;
this.lastRevealerEventTime = 0; this.lastRevealerEventTime = 0;
@@ -38,7 +38,7 @@ class ClapperInterface extends Gtk.Grid
this.attach(this.videoBox, 0, 0, 1, 1); this.attach(this.videoBox, 0, 0, 1, 1);
this.attach(this.controls, 0, 1, 1, 1); this.attach(this.controls, 0, 1, 1, 1);
this.destroySignal = this.connect('destroy', this._onInterfaceDestroy.bind(this)); this.destroySignal = this.connect('destroy', this._onDestroy.bind(this));
} }
addPlayer(player) addPlayer(player)
@@ -102,24 +102,25 @@ class ClapperInterface extends Gtk.Grid
this[`revealer${pos}`].showChild(isShow); this[`revealer${pos}`].showChild(isShow);
} }
setControlsOnVideo(isOnVideo) setFullscreenMode(isFullscreen)
{ {
if(this.controlsInVideo === isOnVideo) if(this.fullscreenMode === isFullscreen)
return; return;
if(isOnVideo) { if(isFullscreen) {
this.remove(this.controls); this.remove(this.controls);
this.controls.pack_start(this.controls.unfullscreenButton.box, false, false, 0); this.revealerBottom.append(this.controls);
this.revealerBottom.addWidget(this.controls);
} }
else { else {
this.revealerBottom.removeWidget(this.controls); this.revealerBottom.remove(this.controls);
this.controls.remove(this.controls.unfullscreenButton.box);
this.attach(this.controls, 0, 1, 1, 1); this.attach(this.controls, 0, 1, 1, 1);
} }
this.controlsInVideo = isOnVideo; this.controls.setFullscreenMode(isFullscreen);
debug(`placed controls in overlay: ${isOnVideo}`); this.showControls(isFullscreen);
this.fullscreenMode = isFullscreen;
debug(`interface in fullscreen mode: ${isFullscreen}`);
} }
updateMediaTracks() updateMediaTracks()
@@ -212,7 +213,7 @@ class ClapperInterface extends Gtk.Grid
} }
continue; continue;
} }
this.controls.addRadioButtons( this.controls.addCheckButtons(
this.controls[`${type}TracksButton`].popoverBox, this.controls[`${type}TracksButton`].popoverBox,
parsedInfo[`${type}Tracks`], parsedInfo[`${type}Tracks`],
activeId activeId
@@ -265,7 +266,7 @@ class ClapperInterface extends Gtk.Grid
}); });
}); });
this.controls.addRadioButtons( this.controls.addCheckButtons(
this.controls.visualizationsButton.popoverBox, this.controls.visualizationsButton.popoverBox,
parsedVisArr, parsedVisArr,
null null
@@ -433,7 +434,7 @@ class ClapperInterface extends Gtk.Grid
this.lastPositionValue = positionSeconds; this.lastPositionValue = positionSeconds;
this._player.seek_seconds(positionSeconds); this._player.seek_seconds(positionSeconds);
if(this.controls.fullscreenMode) if(this.fullscreenMode)
this.updateTime(); this.updateTime();
} }
@@ -469,7 +470,7 @@ class ClapperInterface extends Gtk.Grid
this._player.set_volume(volume); this._player.set_volume(volume);
} }
_onInterfaceDestroy() _onDestroy()
{ {
this.disconnect(this.destroySignal); this.disconnect(this.destroySignal);
this.controls.emit('destroy'); this.controls.emit('destroy');

View File

@@ -220,15 +220,14 @@ class ClapperRevealerBottom extends CustomRevealer
this.revealerBox.add_css_class('osd'); this.revealerBox.add_css_class('osd');
this.set_child(this.revealerBox); this.set_child(this.revealerBox);
//this.revealerBox.show_all();
} }
addWidget(widget) append(widget)
{ {
this.revealerBox.pack_start(widget, false, true, 0); this.revealerBox.append(widget);
} }
removeWidget(widget) remove(widget)
{ {
this.revealerBox.remove(widget); this.revealerBox.remove(widget);
} }

View File

@@ -8,7 +8,8 @@ scale marks {
font-weight: 500; font-weight: 500;
} }
.osd button { .osd button {
margin: 2px; margin-left: 1px;
margin-right: 1px;
min-width: 36px; min-width: 36px;
min-height: 36px; min-height: 36px;
} }