diff --git a/configure.ac b/configure.ac index 1067bc57..74fe3c43 100644 --- a/configure.ac +++ b/configure.ac @@ -22,7 +22,7 @@ dnl keep this in alphabetic order dnl by default, install only extensions that do not change completely the shell experience, dnl that don't require GSettings and that don't require external packages for typelibs dnl (so basically only menus, status icons, search providers, overview tabs, message tray sources, etc.) -DEFAULT_EXTENSIONS="alternative-status-menu apps-menu dock drive-menu gajim places-menu windowsNavigator" +DEFAULT_EXTENSIONS="alternative-status-menu apps-menu dock drive-menu gajim places-menu windowsNavigator workspace-indicator" ALL_EXTENSIONS="$DEFAULT_EXTENSIONS alternate-tab auto-move-windows example native-window-placement systemMonitor user-theme xrandr-indicator" AC_SUBST(ALL_EXTENSIONS, [$ALL_EXTENSIONS]) AC_ARG_ENABLE([extensions], @@ -50,7 +50,7 @@ for e in $enable_extensions; do [AC_MSG_WARN([gnome-desktop-3.0 not found, disabling xrandr-indicator])]) ;; dnl keep this in alphabetic order - alternate-tab|alternative-status-menu|apps-menu|auto-move-windows|dock|drive-menu|example|gajim|native-window-placement|places-menu|user-theme|windowsNavigator) + alternate-tab|alternative-status-menu|apps-menu|auto-move-windows|dock|drive-menu|example|gajim|native-window-placement|places-menu|user-theme|windowsNavigator|workspace-indicator) ENABLED_EXTENSIONS="$ENABLED_EXTENSIONS $e" ;; *) @@ -69,13 +69,14 @@ AC_CONFIG_FILES([ extensions/dock/Makefile extensions/drive-menu/Makefile extensions/example/Makefile - extensions/systemMonitor/Makefile - extensions/windowsNavigator/Makefile extensions/gajim/Makefile extensions/native-window-placement/Makefile extensions/places-menu/Makefile - extensions/xrandr-indicator/Makefile + extensions/systemMonitor/Makefile extensions/user-theme/Makefile + extensions/windowsNavigator/Makefile + extensions/workspace-indicator/Makefile + extensions/xrandr-indicator/Makefile extensions/Makefile Makefile po/Makefile.in diff --git a/extensions/workspace-indicator/Makefile.am b/extensions/workspace-indicator/Makefile.am new file mode 100644 index 00000000..47210de7 --- /dev/null +++ b/extensions/workspace-indicator/Makefile.am @@ -0,0 +1,3 @@ +EXTENSION_ID = workspace-indicator + +include ../../extension.mk diff --git a/extensions/workspace-indicator/extension.js b/extensions/workspace-indicator/extension.js new file mode 100644 index 00000000..1b0d571f --- /dev/null +++ b/extensions/workspace-indicator/extension.js @@ -0,0 +1,98 @@ +const Meta = imports.gi.Meta; +const Clutter = imports.gi.Clutter; +const St = imports.gi.St; +const Lang = imports.lang; +const Mainloop = imports.mainloop; +const PanelMenu = imports.ui.panelMenu; +const PopupMenu = imports.ui.popupMenu; +const Panel = imports.ui.panel; + +const Main = imports.ui.main; + +const Gettext = imports.gettext.domain('gnome-shell-extensions'); +const _ = Gettext.gettext; + +function WorkspaceIndicator() { + this._init.apply(this, arguments); +} + +WorkspaceIndicator.prototype = { + __proto__: PanelMenu.SystemStatusButton.prototype, + + _init: function(){ + PanelMenu.SystemStatusButton.prototype._init.call(this, 'folder'); + + this.statusLabel = new St.Label({ text: this._labelText() }); + this.actor.set_child(this.statusLabel); + + this.workspacesItems = []; + this._workspaceSection = new PopupMenu.PopupMenuSection(); + this.menu.addMenuItem(this._workspaceSection); + global.screen.connect_after('workspace-added', Lang.bind(this,this._createWorkspacesSection)); + global.screen.connect_after('workspace-removed', Lang.bind(this,this._createWorkspacesSection)); + global.screen.connect_after('workspace-switched', Lang.bind(this,this._updateIndicator)); + this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent)); + this._createWorkspacesSection(); + + //styling + this.menu.actor.add_style_class_name('workspace-indicator-shorter'); + }, + + _updateIndicator: function() { + this.statusLabel.set_text(this._labelText()); + }, + + _labelText : function(workspaceIndex) { + if(workspaceIndex == undefined) { + workspaceIndex = global.screen.get_active_workspace().index(); + } + return Meta.prefs_get_workspace_name(workspaceIndex); + }, + + _createWorkspacesSection : function() { + this._workspaceSection.removeAll(); + this.workspacesItems = []; + + let i = 0; + for(; i < global.screen.n_workspaces; i++) { + this.workspacesItems[i] = new PopupMenu.PopupMenuItem(this._labelText(i)); + this._workspaceSection.addMenuItem(this.workspacesItems[i]); + this.workspacesItems[i].workspaceId = i; + this.workspacesItems[i].label_actor = this.statusLabel; + let self = this; + this.workspacesItems[i].connect('activate', Lang.bind(this, function(actor, event) { + this._activate(actor.workspaceId); + })); + } + if(i == 1) { + this._updateIndicator(); + } + }, + + _activate : function (index) { + if(index >= 0 && index < global.screen.n_workspaces) { + let metaWorkspace = global.screen.get_workspace_by_index(index); + metaWorkspace.activate(true); + } + }, + + _onScrollEvent : function(actor, event) { + let direction = event.get_scroll_direction(); + let diff = 0; + if (direction == Clutter.ScrollDirection.DOWN) { + diff = 1; + } else if (direction == Clutter.ScrollDirection.UP) { + diff = -1; + } else { + return; + } + + let newIndex = global.screen.get_active_workspace().index() + diff; + this._activate(newIndex); + }, +} + +function main() { + Panel.STANDARD_TRAY_ICON_ORDER.unshift('workspace-indicator'); + Panel.STANDARD_TRAY_ICON_SHELL_IMPLEMENTATION['workspace-indicator'] = WorkspaceIndicator; +} diff --git a/extensions/workspace-indicator/metadata.json.in b/extensions/workspace-indicator/metadata.json.in new file mode 100644 index 00000000..1d2d04ee --- /dev/null +++ b/extensions/workspace-indicator/metadata.json.in @@ -0,0 +1,9 @@ +{ + "uuid": "@uuid@", + "name": "Workspace Indicator", + "description": "Put an indicator on the panel signaling in which workspace you are, and give you the possibility of switching to another one", + "shell-version": [ "@shell_current@" ], + "localedir": "@LOCALEDIR@", + "original-authors": [ "erick.red@gmail.com" ], + "url": "@url@" +} diff --git a/extensions/workspace-indicator/stylesheet.css b/extensions/workspace-indicator/stylesheet.css new file mode 100644 index 00000000..47ee5351 --- /dev/null +++ b/extensions/workspace-indicator/stylesheet.css @@ -0,0 +1,4 @@ +.workspace-indicator-shorter { + min-width: 25px; + font-size: 10pt; +}