Skip to content

Commit

Permalink
Merge branch 'workspace-name-rework' of https://github.com/autarkper/…
Browse files Browse the repository at this point in the history
  • Loading branch information
clefebvre committed Jul 19, 2012
2 parents 43212cd + 5ce2ff5 commit 80b158b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 31 deletions.
2 changes: 0 additions & 2 deletions js/ui/expo.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,6 @@ Expo.prototype = {

this._shown = false;
this._syncInputMode();

global.settings.set_strv("workspace-names", Main.workspace_names);
},

// hideTemporarily:
Expand Down
33 changes: 24 additions & 9 deletions js/ui/expoThumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,18 @@ ExpoWorkspaceThumbnail.prototype = {
this.title._spacing = 0;
this.titleText = this.title.clutter_text;
this.titleText.connect('key-press-event', Lang.bind(this, this._onTitleKeyPressEvent));
this.titleText.connect('key-focus-in', Lang.bind(this, function() {
this._origTitle = Main.getWorkspaceName(this.metaWorkspace.index());
}));
this.titleText.connect('key-focus-out', Lang.bind(this, function() {
if (!this._undoTitleEdit) {
let newName = this.title.get_text().trim();
Main.setWorkspaceName(this.metaWorkspace.index(), newName);
}
this.title.set_text(Main.getWorkspaceName(this.metaWorkspace.index()));
}));

let workspace_index = this.metaWorkspace.index();
if (workspace_index < Main.workspace_names.length) {
this.title.set_text(Main.workspace_names[workspace_index]);
}
this.title.set_text(Main.getWorkspaceName(this.metaWorkspace.index()));

this._background = Meta.BackgroundActor.new_for_screen(global.screen);
this._contents.add_actor(this._background);
Expand Down Expand Up @@ -273,14 +280,17 @@ ExpoWorkspaceThumbnail.prototype = {
this._slidePosition = 0; // Fully slid in
},

_refreshTitle: function() {
this.title.set_text(Main.getWorkspaceName(this.metaWorkspace.index()));
},

_onTitleKeyPressEvent: function(actor, event) {

if (this.metaWorkspace.index() < Main.workspace_names.length && this.title.get_text() != Main.workspace_names[this.metaWorkspace.index()]) {
Main.workspace_names[this.metaWorkspace.index()] = this.title.get_text();
}

this._undoTitleEdit = false;
let symbol = event.get_key_symbol();
if (symbol === Clutter.Return || symbol === Clutter.Escape) {
if (symbol === Clutter.Escape) {
this._undoTitleEdit = true;
}
global.stage.set_key_focus(this.actor);
return true;
}
Expand Down Expand Up @@ -1160,6 +1170,11 @@ ExpoThumbnailsBox.prototype = {
onCompleteScope: this
});
});

this._iterateStateThumbnails(ThumbnailState.NORMAL, function(thumbnail) {
// keep default workspace names in sync
thumbnail._refreshTitle();
});
this._thumbnails[this._kbThumbnailIndex].showKeyboardSelectedState(true);
},

Expand Down
22 changes: 21 additions & 1 deletion js/ui/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,32 @@ let _checkWorkspacesId = 0;
*/
const LAST_WINDOW_GRACE_TIME = 1000;

function setWorkspaceName(index, name) {
if (index < workspace_names.length) {
name.trim();
if (name != workspace_names[index]) {
workspace_names[index] = name;
global.settings.set_strv("workspace-names", workspace_names);
}
}
}

function getWorkspaceName(index) {
let wsName = index < workspace_names.length ?
workspace_names[index] :
"";
wsName.trim();
return wsName.length > 0 ?
wsName :
_("WORKSPACE") + " " + (index + 1).toString();
}

function _addWorkspace() {
if (dynamicWorkspaces)
return false;
nWorks++;
global.settings.set_int("number-workspaces", nWorks);
workspace_names.push("WORKSPACE " + nWorks);
workspace_names.push("");
_staticWorkspaces();
return true;
}
Expand Down
41 changes: 22 additions & 19 deletions js/ui/windowManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,23 +754,21 @@ WindowManager.prototype = {
showWorkspaceOSD : function() {
if (global.settings.get_boolean("workspace-osd-visible")) {
let current_workspace_index = global.screen.get_active_workspace_index();
if (current_workspace_index < Main.workspace_names.length) {
let monitor = Main.layoutManager.primaryMonitor;
let label = new St.Label({style_class:'workspace-osd'});
label.set_text(Main.workspace_names[current_workspace_index]);
label.set_opacity = 0;
Main.layoutManager.addChrome(label, { visibleInFullscreen: false });
let workspace_osd_x = global.settings.get_int("workspace-osd-x");
let workspace_osd_y = global.settings.get_int("workspace-osd-y");
let x = (monitor.width * workspace_osd_x /100 - label.width/2);
let y = (monitor.height * workspace_osd_y /100 - label.height/2);
label.set_position(x, y);
let duration = global.settings.get_int("workspace-osd-duration") / 1000;
Tweener.addTween(label, { opacity: 255,
time: duration,
transition: 'linear',
onComplete: function() { Main.layoutManager.removeChrome(label); } });
}
let monitor = Main.layoutManager.primaryMonitor;
let label = new St.Label({style_class:'workspace-osd'});
label.set_text(Main.getWorkspaceName(current_workspace_index));
label.set_opacity = 0;
Main.layoutManager.addChrome(label, { visibleInFullscreen: false });
let workspace_osd_x = global.settings.get_int("workspace-osd-x");
let workspace_osd_y = global.settings.get_int("workspace-osd-y");
let x = (monitor.width * workspace_osd_x /100 - label.width/2);
let y = (monitor.height * workspace_osd_y /100 - label.height/2);
label.set_position(x, y);
let duration = global.settings.get_int("workspace-osd-duration") / 1000;
Tweener.addTween(label, { opacity: 255,
time: duration,
transition: 'linear',
onComplete: function() { Main.layoutManager.removeChrome(label); } });
}
},

Expand Down Expand Up @@ -851,13 +849,18 @@ WindowManager.prototype = {
if (screen.n_workspaces == 1)
return;

let current_workspace_index = global.screen.get_active_workspace_index();
if (binding.get_name() == 'switch-to-workspace-left') {
this.actionMoveWorkspaceLeft();
this.showWorkspaceOSD();
if (current_workspace_index !== global.screen.get_active_workspace_index()) {
this.showWorkspaceOSD();
}
}
else if (binding.get_name() == 'switch-to-workspace-right') {
this.actionMoveWorkspaceRight();
this.showWorkspaceOSD();
if (current_workspace_index !== global.screen.get_active_workspace_index()) {
this.showWorkspaceOSD();
}
}
},

Expand Down

0 comments on commit 80b158b

Please sign in to comment.