#
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
const Main = imports.ui.main
|
||||
const Unite = imports.misc.extensionUtils.getCurrentExtension()
|
||||
const Base = Unite.imports.module.BaseModule
|
||||
|
||||
var ActivateWindow = class ActivateWindow extends Base {
|
||||
_onSetup() {
|
||||
this._enableKey = 'autofocus-windows'
|
||||
this._enableValue = true
|
||||
}
|
||||
|
||||
_onActivate() {
|
||||
this._signals.connect(global.display, 'window-demands-attention', 'focusWindow')
|
||||
}
|
||||
|
||||
_focusWindow(actor, win) {
|
||||
Main.activateWindow(win, global.get_current_time())
|
||||
}
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
const Shell = imports.gi.Shell
|
||||
const Main = imports.ui.main
|
||||
const Unite = imports.misc.extensionUtils.getCurrentExtension()
|
||||
const Base = Unite.imports.module.BaseModule
|
||||
|
||||
var ActivitiesButton = class ActivitiesButton extends Base {
|
||||
_onSetup() {
|
||||
this._enableKey = 'hide-activities-button'
|
||||
this._disableValue = 'never'
|
||||
}
|
||||
|
||||
_onInitialize() {
|
||||
this._container = Main.panel.statusArea.activities.container
|
||||
this.appSystem = Shell.AppSystem.get_default()
|
||||
this.winTracker = Shell.WindowTracker.get_default()
|
||||
}
|
||||
|
||||
_onActivate() {
|
||||
this._signals.connect(this.appSystem, 'app-state-changed', 'toggleButton')
|
||||
this._signals.connect(this.winTracker, 'notify::focus-app', 'toggleButton')
|
||||
|
||||
this._signals.connect(Main.overview, 'showing', 'toggleButton')
|
||||
this._signals.connect(Main.overview, 'hiding', 'toggleButton')
|
||||
|
||||
this._toggleButton()
|
||||
}
|
||||
|
||||
_onReset() {
|
||||
this._toggleButton()
|
||||
}
|
||||
|
||||
_onDeactivate() {
|
||||
this._container.show()
|
||||
}
|
||||
|
||||
_toggleButton() {
|
||||
let appMenu = Main.panel.statusArea.appMenu._targetApp != null
|
||||
let overview = Main.overview.visibleTarget
|
||||
let hidden = this._setting == 'always' || (appMenu && !overview)
|
||||
|
||||
if (!hidden && this._settings.get('show-desktop-name'))
|
||||
hidden = !appMenu && !overview
|
||||
|
||||
this._container.visible = !hidden
|
||||
}
|
||||
}
|
@@ -1,73 +0,0 @@
|
||||
const Shell = imports.gi.Shell
|
||||
const Meta = imports.gi.Meta
|
||||
const Main = imports.ui.main
|
||||
const Unite = imports.misc.extensionUtils.getCurrentExtension()
|
||||
const Base = Unite.imports.module.BaseModule
|
||||
const isWindow = Unite.imports.helpers.isWindow
|
||||
const isMaximized = Unite.imports.helpers.isMaximized
|
||||
|
||||
var ApplicationMenu = class ApplicationMenu extends Base {
|
||||
_onSetup() {
|
||||
this._enableKey = 'show-window-title'
|
||||
this._disableValue = 'never'
|
||||
}
|
||||
|
||||
_onInitialize() {
|
||||
this.appMenu = Main.panel.statusArea.appMenu
|
||||
this.winTracker = Shell.WindowTracker.get_default()
|
||||
this.monitorManager = Meta.MonitorManager.get()
|
||||
this._isUpdating = false
|
||||
}
|
||||
|
||||
_onActivate() {
|
||||
this._signals.connect(global.display, 'notify::focus-window', 'updateTitle')
|
||||
this._signals.connect(this.monitorManager, 'monitors-changed', 'updateTitle')
|
||||
|
||||
this._signals.connect(global.window_manager, 'size-change', 'updateTitleText')
|
||||
this._signals.connect(this.appMenu._label, 'notify::text', 'updateTitleText')
|
||||
|
||||
this._updateTitle()
|
||||
}
|
||||
|
||||
_onReset() {
|
||||
this._updateTitle()
|
||||
}
|
||||
|
||||
_handleWindowTitle(win) {
|
||||
if (!isWindow(win) || win._updateTitleID) return
|
||||
|
||||
win._updateTitleID = win.connect(
|
||||
'notify::title', () => { this._updateTitleText() }
|
||||
)
|
||||
}
|
||||
|
||||
_updateTitle() {
|
||||
let focusWindow = global.display.focus_window
|
||||
|
||||
this._handleWindowTitle(focusWindow)
|
||||
this._updateTitleText()
|
||||
}
|
||||
|
||||
_updateTitleText() {
|
||||
if (this._isUpdating) return
|
||||
|
||||
let focusApp = this.winTracker.focus_app
|
||||
let focusWindow = global.display.focus_window
|
||||
let current = this.appMenu._label.get_text()
|
||||
let maximized = isMaximized(focusWindow, this._setting)
|
||||
let always = this._setting == 'always' && focusWindow
|
||||
let title = null
|
||||
|
||||
if (always || maximized)
|
||||
title = focusWindow.title
|
||||
|
||||
if (!title && focusApp)
|
||||
title = focusApp.get_name()
|
||||
|
||||
if (title && title != current) {
|
||||
this._isUpdating = true
|
||||
this.appMenu._label.set_text(title)
|
||||
this._isUpdating = false
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,73 +0,0 @@
|
||||
const Shell = imports.gi.Shell
|
||||
const Main = imports.ui.main
|
||||
const Unite = imports.misc.extensionUtils.getCurrentExtension()
|
||||
const Base = Unite.imports.module.BaseModule
|
||||
const DesktopLabel = Unite.imports.panel.DesktopLabel
|
||||
|
||||
var DesktopName = class DesktopName extends Base {
|
||||
_onSetup() {
|
||||
this._enableKey = 'show-desktop-name'
|
||||
this._enableValue = true
|
||||
}
|
||||
|
||||
_onInitialize() {
|
||||
this.appSystem = Shell.AppSystem.get_default()
|
||||
this.winTracker = Shell.WindowTracker.get_default()
|
||||
}
|
||||
|
||||
_onActivate() {
|
||||
this._signals.connect(this.appSystem, 'app-state-changed', 'toggleLabel')
|
||||
this._signals.connect(this.winTracker, 'notify::focus-app', 'toggleLabel')
|
||||
|
||||
this._signals.connect(Main.overview, 'showing', 'toggleLabel')
|
||||
this._signals.connect(Main.overview, 'hiding', 'toggleLabel')
|
||||
|
||||
this._settings.connect('desktop-name-text', 'setLabelText')
|
||||
|
||||
this._createLabel()
|
||||
}
|
||||
|
||||
_onDeactivate() {
|
||||
if (!this._label) return
|
||||
|
||||
this._label.destroy()
|
||||
this._label = null
|
||||
}
|
||||
|
||||
_visibleWindows() {
|
||||
let windows = global.get_window_actors().find(win => {
|
||||
let visible = win.metaWindow.showing_on_its_workspace()
|
||||
let skipped = win.metaWindow.skip_taskbar
|
||||
|
||||
return visible && !skipped
|
||||
})
|
||||
|
||||
return windows
|
||||
}
|
||||
|
||||
_setLabelText() {
|
||||
let text = this._settings.get('desktop-name-text')
|
||||
this._label.setText(text)
|
||||
}
|
||||
|
||||
_toggleLabel() {
|
||||
let appMenu = Main.panel.statusArea.appMenu._targetApp != null
|
||||
let overview = Main.overview.visibleTarget
|
||||
let visible = !appMenu && !overview
|
||||
|
||||
if (visible)
|
||||
visible = visible && !this._visibleWindows()
|
||||
|
||||
this._label.setVisible(visible)
|
||||
}
|
||||
|
||||
_createLabel() {
|
||||
if (this._label) return
|
||||
|
||||
this._label = new DesktopLabel()
|
||||
Main.panel.addToStatusArea('uniteDesktopLabel', this._label, 1, 'left')
|
||||
|
||||
this._setLabelText()
|
||||
this._toggleLabel()
|
||||
}
|
||||
}
|
@@ -1,87 +0,0 @@
|
||||
const Gi = imports._gi
|
||||
const Clutter = imports.gi.Clutter
|
||||
const Main = imports.ui.main
|
||||
const Unite = imports.misc.extensionUtils.getCurrentExtension()
|
||||
const Base = Unite.imports.module.BaseModule
|
||||
|
||||
var ExtendLeftBox = class ExtendLeftBox extends Base {
|
||||
_onSetup() {
|
||||
this._enableKey = 'extend-left-box'
|
||||
this._enableValue = true
|
||||
}
|
||||
|
||||
_onActivate() {
|
||||
this._oldAllocate = Main.panel.__proto__.vfunc_allocate
|
||||
|
||||
Main.panel.__proto__[Gi.hook_up_vfunc_symbol]('allocate', (box, flags) => {
|
||||
Main.panel.vfunc_allocate.call(Main.panel, box, flags)
|
||||
this._extendBox(Main.panel, box, flags)
|
||||
})
|
||||
}
|
||||
|
||||
_onDeactivate() {
|
||||
if (this._oldAllocate) {
|
||||
Main.panel.__proto__[Gi.hook_up_vfunc_symbol]('allocate', this._oldAllocate)
|
||||
this._oldAllocate = null
|
||||
}
|
||||
}
|
||||
|
||||
_onReload() {
|
||||
Main.panel.queue_relayout()
|
||||
}
|
||||
|
||||
_extendBox(actor, box, flags) {
|
||||
let leftBox = Main.panel._leftBox
|
||||
let centerBox = Main.panel._centerBox
|
||||
let rightBox = Main.panel._rightBox
|
||||
|
||||
let allocWidth = box.x2 - box.x1
|
||||
let allocHeight = box.y2 - box.y1
|
||||
|
||||
let [leftMinWidth, leftNaturalWidth] = leftBox.get_preferred_width(-1)
|
||||
let [centerMinWidth, centerNaturalWidth] = centerBox.get_preferred_width(-1)
|
||||
let [rightMinWidth, rightNaturalWidth] = rightBox.get_preferred_width(-1)
|
||||
|
||||
let sideWidth = allocWidth - rightNaturalWidth - centerNaturalWidth
|
||||
let childBox = new Clutter.ActorBox()
|
||||
|
||||
childBox.y1 = 0
|
||||
childBox.y2 = allocHeight
|
||||
|
||||
if (actor.get_text_direction() == Clutter.TextDirection.RTL) {
|
||||
childBox.x1 = allocWidth - Math.min(Math.floor(sideWidth), leftNaturalWidth)
|
||||
childBox.x2 = allocWidth
|
||||
} else {
|
||||
childBox.x1 = 0
|
||||
childBox.x2 = Math.min(Math.floor(sideWidth), leftNaturalWidth)
|
||||
}
|
||||
|
||||
leftBox.allocate(childBox, flags)
|
||||
|
||||
childBox.y1 = 0
|
||||
childBox.y2 = allocHeight
|
||||
|
||||
if (actor.get_text_direction() == Clutter.TextDirection.RTL) {
|
||||
childBox.x1 = rightNaturalWidth
|
||||
childBox.x2 = childBox.x1 + centerNaturalWidth
|
||||
} else {
|
||||
childBox.x1 = allocWidth - centerNaturalWidth - rightNaturalWidth
|
||||
childBox.x2 = childBox.x1 + centerNaturalWidth
|
||||
}
|
||||
|
||||
centerBox.allocate(childBox, flags)
|
||||
|
||||
childBox.y1 = 0
|
||||
childBox.y2 = allocHeight
|
||||
|
||||
if (actor.get_text_direction() == Clutter.TextDirection.RTL) {
|
||||
childBox.x1 = 0
|
||||
childBox.x2 = rightNaturalWidth
|
||||
} else {
|
||||
childBox.x1 = allocWidth - rightNaturalWidth
|
||||
childBox.x2 = allocWidth
|
||||
}
|
||||
|
||||
rightBox.allocate(childBox, flags)
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
const Clutter = imports.gi.Clutter
|
||||
const Main = imports.ui.main
|
||||
const Unite = imports.misc.extensionUtils.getCurrentExtension()
|
||||
const Base = Unite.imports.module.BaseModule
|
||||
const scaleSize = Unite.imports.helpers.scaleSize
|
||||
|
||||
var MessageTray = class MessageTray extends Base {
|
||||
_onSetup() {
|
||||
this._enableKey = 'notifications-position'
|
||||
this._disableValue = 'center'
|
||||
}
|
||||
|
||||
_onInitialize() {
|
||||
this._banner = Main.messageTray._bannerBin
|
||||
}
|
||||
|
||||
_onActivate() {
|
||||
let mappings = { center: 'CENTER', left: 'START', right: 'END' }
|
||||
let position = mappings[this._setting] || 'CENTER'
|
||||
|
||||
this._banner.set_x_align(Clutter.ActorAlign[position])
|
||||
this._banner.set_width(scaleSize(390))
|
||||
}
|
||||
|
||||
_onDeactivate() {
|
||||
this._banner.set_x_align(Clutter.ActorAlign.CENTER)
|
||||
this._banner.set_width(-1)
|
||||
}
|
||||
}
|
@@ -1,210 +0,0 @@
|
||||
const Gtk = imports.gi.Gtk
|
||||
const Main = imports.ui.main
|
||||
const Unite = imports.misc.extensionUtils.getCurrentExtension()
|
||||
const Base = Unite.imports.module.BaseModule
|
||||
const minorVersion = Unite.imports.helpers.minorVersion
|
||||
|
||||
var ThemeMods = class ThemeMods extends Base {
|
||||
_onInitialize() {
|
||||
this.gtkSettings = Gtk.Settings.get_default()
|
||||
this._extraSpace = minorVersion < 34
|
||||
this._mainStyle = Main.uiGroup.get_style()
|
||||
this._panelStyle = Main.panel.get_style()
|
||||
this._appMenu = Main.panel.statusArea.appMenu
|
||||
this._aggMenu = Main.panel.statusArea.aggregateMenu
|
||||
this._leftBox = Main.panel._leftBox
|
||||
this._centerBox = Main.panel._centerBox
|
||||
this._rightBox = Main.panel._rightBox
|
||||
}
|
||||
|
||||
_onActivate() {
|
||||
this._signals.connect(this.gtkSettings, 'notify::gtk-font-name', 'setPanelStyle')
|
||||
this._signals.connect(this._leftBox, 'actor_added', 'removePanelArrows')
|
||||
this._signals.connect(this._centerBox, 'actor_added', 'removePanelArrows')
|
||||
this._signals.connect(this._rightBox, 'actor_added', 'removePanelArrows')
|
||||
|
||||
this._settings.connect('use-system-fonts', 'setPanelStyle')
|
||||
this._settings.connect('reduce-panel-spacing', 'setPanelStyle')
|
||||
this._settings.connect('hide-app-menu-icon', 'toggleAppMenuIcon')
|
||||
this._settings.connect('hide-dropdown-arrows', 'togglePanelArrows')
|
||||
this._settings.connect('hide-aggregate-menu-arrow', 'toggleAggMenuArrow')
|
||||
this._settings.connect('hide-app-menu-arrow', 'toggleAppMenuArrow')
|
||||
|
||||
this._setExtraSpace()
|
||||
|
||||
this._toggleAppMenuIcon()
|
||||
this._togglePanelArrows()
|
||||
this._toggleAggMenuArrow()
|
||||
this._toggleAppMenuArrow()
|
||||
|
||||
this._setPanelStyle()
|
||||
}
|
||||
|
||||
_onDeactivate() {
|
||||
this._unsetExtraSpace()
|
||||
|
||||
this._resetAppMenuIcon()
|
||||
this._resetPanelArrows()
|
||||
this._resetAggMenuArrow()
|
||||
this._resetAppMenuArrow()
|
||||
|
||||
this._unsetPanelStyle()
|
||||
}
|
||||
|
||||
_setExtraSpace() {
|
||||
if (this._extraSpace) {
|
||||
this._addClass('extra-spacing')
|
||||
}
|
||||
}
|
||||
|
||||
_unsetExtraSpace() {
|
||||
if (this._extraSpace) {
|
||||
this._removeClass('extra-spacing')
|
||||
}
|
||||
}
|
||||
|
||||
_setPanelStyle() {
|
||||
this._unsetPanelStyle()
|
||||
|
||||
const fonts = this._settings.get('use-system-fonts')
|
||||
const space = this._settings.get('reduce-panel-spacing')
|
||||
|
||||
if (!fonts && !space) return
|
||||
|
||||
if (fonts) {
|
||||
const gtkFont = this.gtkSettings.gtk_font_name
|
||||
const cssFont = gtkFont.replace(/\s\d+$/, '')
|
||||
|
||||
Main.uiGroup.set_style(`font-family: ${cssFont};`)
|
||||
this._addClass('system-fonts')
|
||||
}
|
||||
|
||||
if (space) {
|
||||
this._addClass('small-spacing')
|
||||
}
|
||||
|
||||
Main.panel.set_style('font-size: 11.25pt;')
|
||||
}
|
||||
|
||||
_unsetPanelStyle() {
|
||||
this._removeClass('small-spacing')
|
||||
this._removeClass('system-fonts')
|
||||
|
||||
Main.uiGroup.set_style(this._mainStyle)
|
||||
Main.panel.set_style(this._panelStyle)
|
||||
}
|
||||
|
||||
_toggleAppMenuIcon() {
|
||||
const enabled = this._settings.get('hide-app-menu-icon')
|
||||
|
||||
if (enabled) {
|
||||
this._appMenu._iconBox.hide()
|
||||
} else {
|
||||
this._resetAppMenuIcon()
|
||||
}
|
||||
}
|
||||
|
||||
_resetAppMenuIcon() {
|
||||
this._appMenu._iconBox.show()
|
||||
}
|
||||
|
||||
_getWidgetArrow(widget) {
|
||||
let arrow = widget._arrow
|
||||
|
||||
if (!arrow) {
|
||||
const last = widget.get_n_children() - 1
|
||||
const actor = widget.get_children()[last]
|
||||
|
||||
if (!actor) return
|
||||
|
||||
if (actor.has_style_class_name && actor.has_style_class_name('popup-menu-arrow'))
|
||||
arrow = actor
|
||||
else
|
||||
arrow = this._getWidgetArrow(actor)
|
||||
}
|
||||
|
||||
if (arrow && !widget.hasOwnProperty('_arrow'))
|
||||
widget._arrow = arrow
|
||||
|
||||
return arrow
|
||||
}
|
||||
|
||||
_toggleWidgetArrow(widget, hide) {
|
||||
if (!widget) return
|
||||
|
||||
const arrow = this._getWidgetArrow(widget)
|
||||
if (!arrow) return
|
||||
|
||||
if (hide && !widget._arrowHandled) {
|
||||
arrow.visible = false
|
||||
widget._arrowHandled = true
|
||||
}
|
||||
|
||||
if (!hide && widget._arrowHandled) {
|
||||
arrow.visible = true
|
||||
delete widget._arrowHandled
|
||||
}
|
||||
}
|
||||
|
||||
_removePanelArrows() {
|
||||
for (const [name, widget] of Object.entries(Main.panel.statusArea)) {
|
||||
if (name != 'aggregateMenu' && name != 'appMenu') {
|
||||
this._toggleWidgetArrow(widget, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_resetPanelArrows() {
|
||||
for (const [name, widget] of Object.entries(Main.panel.statusArea)) {
|
||||
if (name != 'aggregateMenu' && name != 'appMenu') {
|
||||
this._toggleWidgetArrow(widget, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_togglePanelArrows() {
|
||||
const enabled = this._settings.get('hide-dropdown-arrows')
|
||||
|
||||
if (enabled) {
|
||||
this._removePanelArrows()
|
||||
} else {
|
||||
this._resetPanelArrows()
|
||||
}
|
||||
}
|
||||
|
||||
_toggleAggMenuArrow() {
|
||||
const enabled = this._settings.get('hide-aggregate-menu-arrow')
|
||||
|
||||
if (enabled) {
|
||||
this._toggleWidgetArrow(this._aggMenu, true)
|
||||
} else {
|
||||
this._resetAggMenuArrow()
|
||||
}
|
||||
}
|
||||
|
||||
_resetAggMenuArrow() {
|
||||
this._toggleWidgetArrow(this._aggMenu, false)
|
||||
}
|
||||
|
||||
_toggleAppMenuArrow() {
|
||||
const enabled = this._settings.get('hide-app-menu-arrow')
|
||||
|
||||
if (enabled) {
|
||||
this._toggleWidgetArrow(this._appMenu, true)
|
||||
} else {
|
||||
this._resetAppMenuArrow()
|
||||
}
|
||||
}
|
||||
|
||||
_resetAppMenuArrow() {
|
||||
this._toggleWidgetArrow(this._appMenu, false)
|
||||
}
|
||||
|
||||
_addClass(name) {
|
||||
Main.panel._addStyleClassName(name)
|
||||
}
|
||||
|
||||
_removeClass(name) {
|
||||
Main.panel._removeStyleClassName(name)
|
||||
}
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
const System = imports.system
|
||||
const Clutter = imports.gi.Clutter
|
||||
const Shell = imports.gi.Shell
|
||||
const Main = imports.ui.main
|
||||
const Unite = imports.misc.extensionUtils.getCurrentExtension()
|
||||
const Base = Unite.imports.module.BaseModule
|
||||
const TrayIndicator = Unite.imports.panel.TrayIndicator
|
||||
const scaleSize = Unite.imports.helpers.scaleSize
|
||||
|
||||
var TopIcons = class TopIcons extends Base {
|
||||
_onSetup() {
|
||||
this._enableKey = 'show-legacy-tray'
|
||||
this._enableValue = true
|
||||
}
|
||||
|
||||
_onActivate() {
|
||||
this._settings.connect('greyscale-tray-icons', 'desaturateIcons')
|
||||
|
||||
this._createContainer()
|
||||
this._createTray()
|
||||
}
|
||||
|
||||
_onDeactivate() {
|
||||
this._destroyContainer()
|
||||
this._destroyTray()
|
||||
}
|
||||
|
||||
_createTray() {
|
||||
this._tray = new Shell.TrayManager()
|
||||
|
||||
this._tray.connect('tray-icon-added', (trayManager, icon) => {
|
||||
this._indicators.addIcon(icon)
|
||||
this._desaturateIcon(icon)
|
||||
})
|
||||
|
||||
this._tray.connect('tray-icon-removed', (trayManager, icon) => {
|
||||
this._indicators.removeIcon(icon)
|
||||
})
|
||||
|
||||
this._tray.manage_screen(Main.panel)
|
||||
}
|
||||
|
||||
_destroyTray() {
|
||||
this._tray = null
|
||||
System.gc()
|
||||
}
|
||||
|
||||
_createContainer() {
|
||||
if (this._indicators) return
|
||||
|
||||
this._indicators = new TrayIndicator({ size: scaleSize(20) })
|
||||
Main.panel.addToStatusArea('uniteTrayIndicator', this._indicators)
|
||||
}
|
||||
|
||||
_destroyContainer() {
|
||||
if (!this._indicators) return
|
||||
|
||||
this._indicators.destroy()
|
||||
this._indicators = null
|
||||
}
|
||||
|
||||
_desaturateIcon(icon) {
|
||||
let greyscale = this._settings.get('greyscale-tray-icons')
|
||||
icon.clear_effects()
|
||||
|
||||
if (!greyscale) return
|
||||
|
||||
let desEffect = new Clutter.DesaturateEffect({ factor : 1.0 })
|
||||
let briEffect = new Clutter.BrightnessContrastEffect({})
|
||||
|
||||
briEffect.set_brightness(0.2)
|
||||
briEffect.set_contrast(0.3)
|
||||
|
||||
icon.add_effect_with_name('desaturate', desEffect)
|
||||
icon.add_effect_with_name('brightness-contrast', briEffect)
|
||||
}
|
||||
|
||||
_desaturateIcons() {
|
||||
if (!this._indicators) return
|
||||
|
||||
this._indicators.forEach(icon => { this._desaturateIcon(icon) })
|
||||
}
|
||||
}
|
@@ -1,181 +0,0 @@
|
||||
const St = imports.gi.St
|
||||
const Shell = imports.gi.Shell
|
||||
const Meta = imports.gi.Meta
|
||||
const Main = imports.ui.main
|
||||
const Unite = imports.misc.extensionUtils.getCurrentExtension()
|
||||
const Base = Unite.imports.module.BaseModule
|
||||
const WindowControls = Unite.imports.panel.WindowControls
|
||||
const isWindow = Unite.imports.helpers.isWindow
|
||||
const isMaximized = Unite.imports.helpers.isMaximized
|
||||
const loadStyles = Unite.imports.helpers.loadStyles
|
||||
const unloadStyles = Unite.imports.helpers.unloadStyles
|
||||
|
||||
var WindowButtons = class WindowButtons extends Base {
|
||||
_onSetup() {
|
||||
this._enableKey = 'show-window-buttons'
|
||||
this._disableValue = 'never'
|
||||
}
|
||||
|
||||
_onInitialize() {
|
||||
this.monitorManager = Meta.MonitorManager.get()
|
||||
}
|
||||
|
||||
_onActivate() {
|
||||
this._signals.connect(global.display, 'notify::focus-window', 'toggleButtons')
|
||||
this._signals.connect(global.window_manager, 'size-change', 'toggleButtons')
|
||||
this._signals.connect(global.window_manager, 'destroy', 'toggleButtons')
|
||||
this._signals.connect(this.monitorManager, 'monitors-changed', 'toggleButtons')
|
||||
|
||||
this._signals.connect(Main.overview, 'showing', 'toggleButtons')
|
||||
this._signals.connect(Main.overview, 'hiding', 'toggleButtons')
|
||||
|
||||
this._settings.connect('window-buttons-theme', 'updateTheme')
|
||||
this._settings.connect('button-layout', 'updateButtons')
|
||||
this._settings.connect('window-buttons-placement', 'updateButtons')
|
||||
this._settings.connect('restrict-to-primary-screen', 'updateButtons')
|
||||
|
||||
this._createButtons()
|
||||
this._toggleButtons()
|
||||
this._loadTheme()
|
||||
}
|
||||
|
||||
_onReset() {
|
||||
this._toggleButtons()
|
||||
}
|
||||
|
||||
_onDeactivate() {
|
||||
this._unloadTheme()
|
||||
this._destroyButtons()
|
||||
}
|
||||
|
||||
_createButtons() {
|
||||
let buttons = this._settings.get('window-buttons-layout')
|
||||
let side = this._settings.get('window-buttons-position')
|
||||
let place = this._settings.get('window-buttons-placement')
|
||||
let index = side == 'left' ? 1 : -1
|
||||
|
||||
if (!buttons || this._controls) return
|
||||
|
||||
if ((place == 'right' || place == 'last') && side == 'left') {
|
||||
buttons = buttons.reverse()
|
||||
}
|
||||
|
||||
if (place == 'left' || place == 'first') {
|
||||
side = 'left'
|
||||
index = 0
|
||||
}
|
||||
|
||||
if (place == 'right' || place == 'last') {
|
||||
side = 'right'
|
||||
index = -1
|
||||
}
|
||||
|
||||
this._controls = new WindowControls()
|
||||
|
||||
this._controls.addButtons(buttons, (actor, event) => {
|
||||
this._onButtonClick(actor, event)
|
||||
})
|
||||
|
||||
Main.panel.addToStatusArea('uniteWindowControls', this._controls, index, side)
|
||||
|
||||
const widget = this._controls.get_parent()
|
||||
const appMenu = Main.panel.statusArea.appMenu.get_parent()
|
||||
const aggMenu = Main.panel.statusArea.aggregateMenu.get_parent()
|
||||
|
||||
if (side == 'left' && place != 'first') {
|
||||
Main.panel._leftBox.set_child_below_sibling(widget, appMenu)
|
||||
}
|
||||
|
||||
if (side == 'right' && place != 'last') {
|
||||
Main.panel._rightBox.set_child_below_sibling(widget, aggMenu)
|
||||
}
|
||||
}
|
||||
|
||||
_destroyButtons() {
|
||||
if (!this._controls) return
|
||||
|
||||
this._controls.destroy()
|
||||
this._controls = null
|
||||
}
|
||||
|
||||
_updateButtons() {
|
||||
this._destroyButtons()
|
||||
this._createButtons()
|
||||
}
|
||||
|
||||
_updateTheme() {
|
||||
this._unloadTheme()
|
||||
this._loadTheme()
|
||||
}
|
||||
|
||||
_loadTheme() {
|
||||
if (this._themeFile || !this._controls) return
|
||||
|
||||
this._themeName = this._settings.get('window-buttons-theme')
|
||||
this._themeFile = loadStyles(`themes/${this._themeName}/stylesheet.css`)
|
||||
|
||||
this._controls.add_style_class_name(`${this._themeName}-buttons`)
|
||||
}
|
||||
|
||||
_unloadTheme() {
|
||||
if (!this._themeFile || !this._controls) return
|
||||
|
||||
this._controls.remove_style_class_name(`${this._themeName}-buttons`)
|
||||
|
||||
this._themeName = this._settings.get('window-buttons-theme')
|
||||
this._themeFile = unloadStyles(this._themeFile)
|
||||
}
|
||||
|
||||
_onButtonClick(actor, event) {
|
||||
let focusWindow = global.display.focus_window
|
||||
if (!focusWindow) return
|
||||
|
||||
switch (actor._windowAction) {
|
||||
case 'minimize': return this._minimizeWindow(focusWindow)
|
||||
case 'maximize': return this._maximizeWindow(focusWindow)
|
||||
case 'close': return this._closeWindow(focusWindow)
|
||||
}
|
||||
}
|
||||
|
||||
_minimizeWindow(win) {
|
||||
if (!win.minimized) win.minimize()
|
||||
}
|
||||
|
||||
_maximizeWindow(win) {
|
||||
let bothMaximized = Meta.MaximizeFlags.BOTH
|
||||
let maximizeState = win.get_maximized()
|
||||
|
||||
if (maximizeState === bothMaximized)
|
||||
win.unmaximize(bothMaximized)
|
||||
else
|
||||
win.maximize(bothMaximized)
|
||||
}
|
||||
|
||||
_closeWindow(win) {
|
||||
win.delete(global.get_current_time())
|
||||
}
|
||||
|
||||
_toggleButtons() {
|
||||
if (!this._controls) return
|
||||
|
||||
let focusWindow = global.display.focus_window
|
||||
let overview = Main.overview.visibleTarget
|
||||
let valid = isWindow(focusWindow)
|
||||
let visible = false
|
||||
|
||||
if (!overview && valid) {
|
||||
let maxed = isMaximized(focusWindow, this._setting)
|
||||
let always = this._setting == 'always' && focusWindow
|
||||
|
||||
visible = always || maxed
|
||||
} else {
|
||||
let target = Main.panel.statusArea.appMenu._targetApp
|
||||
let state = target != null && target.get_state()
|
||||
let running = state == Shell.AppState.RUNNING
|
||||
|
||||
visible = running && !overview
|
||||
}
|
||||
|
||||
this._controls.setVisible(visible)
|
||||
}
|
||||
}
|
@@ -1,196 +0,0 @@
|
||||
const ByteArray = imports.byteArray
|
||||
const GLib = imports.gi.GLib
|
||||
const Meta = imports.gi.Meta
|
||||
const Util = imports.misc.util
|
||||
const Unite = imports.misc.extensionUtils.getCurrentExtension()
|
||||
const Base = Unite.imports.module.BaseModule
|
||||
const getWindowXID = Unite.imports.helpers.getWindowXID
|
||||
const isWindow = Unite.imports.helpers.isWindow
|
||||
const isMaximized = Unite.imports.helpers.isMaximized
|
||||
const loadUserStyles = Unite.imports.helpers.loadUserStyles
|
||||
|
||||
var WindowDecoration = class WindowDecoration extends Base {
|
||||
_onSetup() {
|
||||
this._enableKey = 'hide-window-titlebars'
|
||||
this._disableValue = 'never'
|
||||
}
|
||||
|
||||
_onInitialize() {
|
||||
this.monitorManager = Meta.MonitorManager.get()
|
||||
}
|
||||
|
||||
_onActivate() {
|
||||
this._signals.connect(global.display, 'notify::focus-window', 'updateTitlebar')
|
||||
this._signals.connect(global.window_manager, 'size-change', 'updateTitlebar')
|
||||
this._signals.connect(this.monitorManager, 'monitors-changed', 'undecorateWindows')
|
||||
|
||||
this._settings.connect('hide-window-titlebars', 'updateUserStyles')
|
||||
this._settings.connect('button-layout', 'updateUserStyles')
|
||||
this._settings.connect('restrict-to-primary-screen', 'undecorateWindows')
|
||||
|
||||
this._updateUserStyles()
|
||||
this._undecorateWindows()
|
||||
}
|
||||
|
||||
_onDeactivate() {
|
||||
this._removeUserStyles()
|
||||
this._decorateWindows()
|
||||
}
|
||||
|
||||
_onReset() {
|
||||
this._removeUserStyles()
|
||||
this._updateUserStyles()
|
||||
|
||||
this._undecorateWindows()
|
||||
}
|
||||
|
||||
_getWindowXID(win) {
|
||||
win._windowXID = win._windowXID || getWindowXID(win)
|
||||
return win._windowXID
|
||||
}
|
||||
|
||||
_getHintValue(win, hint) {
|
||||
let winId = this._getWindowXID(win)
|
||||
if (!winId) return
|
||||
|
||||
let result = GLib.spawn_command_line_sync(`xprop -id ${winId} ${hint}`)
|
||||
let string = ByteArray.toString(result[1])
|
||||
if (!string.match(/=/)) return
|
||||
|
||||
string = string.split('=')[1].trim().split(',').map(part => {
|
||||
part = part.trim()
|
||||
return part.match(/\dx/) ? part : `0x${part}`
|
||||
})
|
||||
|
||||
return string
|
||||
}
|
||||
|
||||
_setHintValue(win, hint, value) {
|
||||
let winId = this._getWindowXID(win)
|
||||
if (!winId) return
|
||||
|
||||
Util.spawn(['xprop', '-id', winId, '-f', hint, '32c', '-set', hint, value])
|
||||
}
|
||||
|
||||
_getMotifHints(win) {
|
||||
if (!win._uniteOriginalState) {
|
||||
let state = this._getHintValue(win, '_UNITE_ORIGINAL_STATE')
|
||||
|
||||
if (!state) {
|
||||
state = this._getHintValue(win, '_MOTIF_WM_HINTS')
|
||||
state = state || ['0x2', '0x0', '0x1', '0x0', '0x0']
|
||||
|
||||
this._setHintValue(win, '_UNITE_ORIGINAL_STATE', state.join(', '))
|
||||
}
|
||||
|
||||
win._uniteOriginalState = state
|
||||
}
|
||||
|
||||
return win._uniteOriginalState
|
||||
}
|
||||
|
||||
_getAllWindows() {
|
||||
let windows = global.get_window_actors().map(win => win.meta_window)
|
||||
return windows.filter(win => this._handleWindow(win))
|
||||
}
|
||||
|
||||
_handleWindow(win) {
|
||||
let handleWin = false
|
||||
if (!isWindow(win)) return
|
||||
|
||||
let state = this._getMotifHints(win)
|
||||
handleWin = !win.is_client_decorated()
|
||||
handleWin = handleWin && (state[2] != '0x2' && state[2] != '0x0')
|
||||
|
||||
return handleWin
|
||||
}
|
||||
|
||||
_toggleDecorations(win, hide) {
|
||||
let winId = this._getWindowXID(win)
|
||||
if (!winId) return
|
||||
|
||||
let prop = '_MOTIF_WM_HINTS'
|
||||
let flag = '0x2, 0x0, %s, 0x0, 0x0'
|
||||
let value = hide ? flag.format('0x2') : flag.format('0x1')
|
||||
|
||||
Util.spawn(['xprop', '-id', winId, '-f', prop, '32c', '-set', prop, value])
|
||||
}
|
||||
|
||||
_resetDecorations(win) {
|
||||
if (!this._handleWindow(win))
|
||||
return
|
||||
|
||||
this._toggleDecorations(win, false)
|
||||
|
||||
delete win._decorationOFF
|
||||
delete win._windowXID
|
||||
}
|
||||
|
||||
_updateTitlebar() {
|
||||
let focusWindow = global.display.focus_window
|
||||
if (!focusWindow) return
|
||||
|
||||
this._toggleTitlebar(focusWindow)
|
||||
}
|
||||
|
||||
_showTitlebar(win) {
|
||||
if (!win._decorationOFF) return
|
||||
|
||||
win._decorationOFF = false
|
||||
this._toggleDecorations(win, false)
|
||||
}
|
||||
|
||||
_hideTitlebar(win) {
|
||||
if (win._decorationOFF) return
|
||||
|
||||
win._decorationOFF = true
|
||||
this._toggleDecorations(win, true)
|
||||
}
|
||||
|
||||
_toggleTitlebar(win) {
|
||||
if (!this._handleWindow(win))
|
||||
return
|
||||
|
||||
let maxed = isMaximized(win, this._setting)
|
||||
let always = this._setting == 'always'
|
||||
|
||||
if (always || maxed)
|
||||
this._hideTitlebar(win)
|
||||
else
|
||||
this._showTitlebar(win)
|
||||
}
|
||||
|
||||
_getCssImports() {
|
||||
let position = this._settings.get('window-buttons-position')
|
||||
let filePath = `${Unite.path}/styles/buttons-${position}`
|
||||
let maximized = `@import url('${filePath}.css');\n`
|
||||
let tiled = `@import url('${filePath}-tiled.css');\n`
|
||||
let always = `@import url('${filePath}-always.css');\n`
|
||||
|
||||
switch (this._setting) {
|
||||
case 'both': return maximized + tiled
|
||||
case 'maximized': return maximized
|
||||
case 'tiled': return tiled
|
||||
case 'always': return always
|
||||
}
|
||||
}
|
||||
|
||||
_updateUserStyles() {
|
||||
let styles = this._getCssImports()
|
||||
loadUserStyles(styles || '')
|
||||
}
|
||||
|
||||
_removeUserStyles() {
|
||||
loadUserStyles('')
|
||||
}
|
||||
|
||||
_undecorateWindows() {
|
||||
let windows = this._getAllWindows()
|
||||
windows.forEach(win => { this._toggleTitlebar(win) })
|
||||
}
|
||||
|
||||
_decorateWindows() {
|
||||
let windows = this._getAllWindows()
|
||||
windows.forEach(win => { this._resetDecorations(win) })
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user