Skip to content

Commit

Permalink
Version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfm committed Aug 4, 2015
1 parent daeda0d commit e2572ca
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 51 deletions.
81 changes: 42 additions & 39 deletions [email protected]/app_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ let appMenu = null;
*/
function updateAppMenu() {
let win = global.display.focus_window;

if(!win) {
return false;
}

let title = win.title;

// Not the topmost maximized window.
if(win !== Util.getWindow()) {
let app = Shell.WindowTracker.get_default().get_window_app(win);
title = app.get_name();
}

LOG('Override title ' + title);
appMenu._label.setText(title);
tooltip.text = title;

return false;
}

Expand All @@ -53,13 +53,13 @@ function changeActiveWindow(win) {
if(win === activeWindow) {
return;
}

if(activeWindow) {
activeWindow.disconnect(awCallbackID);
}

activeWindow = win;

if(win) {
awCallbackID = win.connect('notify::title', updateAppMenu);
updateAppMenu();
Expand All @@ -70,14 +70,16 @@ function changeActiveWindow(win) {
* Focus change
*/
function onFocusChange() {
if (!Shell.WindowTracker.get_default().focus_app &&
global.stage_input_mode == Shell.StageInputMode.FOCUSED) {
let input_mode_check = (global.stage_input_mode === undefined)
? true
: global.stage_input_mode == Shell.StageInputMode.FOCUSED;
if (!Shell.WindowTracker.get_default().focus_app && input_mode_check) {
// If the app has just lost focus to the panel, pretend
// nothing happened; otherwise you can't keynav to the
// app menu.
return false;
}

changeActiveWindow(global.display.focus_window);
return false;
}
Expand All @@ -100,24 +102,24 @@ function onHover(actor) {
if(showTooltip === hover) {
return false;
}

// We are not in the right state, let's fix that.
showTooltip = hover;

if (showTooltip) {
tooltipDelayCallbackID = Mainloop.timeout_add(SHOW_DELAY, function() {
if (!showTooltip) {
WARN('showTooltip is false and delay callback ran.');
}

let label = appMenu._label._label;

if(!label.get_clutter_text().get_layout().is_ellipsized()) {
// Do not need to hide.
tooltipDelayCallbackID = 0;
return false;
}

Main.uiGroup.add_actor(tooltip);
menuCallbackID = appMenu.menu.connect('open-state-changed', function(menu, open) {
if(open) {
Expand All @@ -126,35 +128,35 @@ function onHover(actor) {
Main.uiGroup.add_actor(tooltip);
}
});

[bx, by] = label.get_transformed_position();
[w, h] = label.get_transformed_size();

let y = by + h + 5;
let x = bx - Math.round((tooltip.get_width() - w)/2);
tooltip.opacity = 0;
tooltip.set_position(x, y);

LOG('show title tooltip');
Tweener.removeTweens(tooltip);
Tweener.addTween(tooltip, {
opacity: 255,
time: SHOW_DURATION,
transition: 'easeOutQuad',
});

return false;
});
} else if(tooltipDelayCallbackID > 0) {
if(!Mainloop.source_remove(tooltipDelayCallbackID)) {
// If the event ran, then we hide.
LOG('hide title tooltip');

if(menuCallbackID) {
appMenu.menu.disconnect(menuCallbackID);
menuCallbackID = 0;
}

Tweener.removeTweens(tooltip);
Tweener.addTween(tooltip, {
opacity: 0,
Expand All @@ -165,10 +167,10 @@ function onHover(actor) {
}
});
}

tooltipDelayCallbackID = 0;
}

return false;
}

Expand All @@ -187,57 +189,58 @@ let focusCallbackID = 0;
let tooltipCallbackID = 0;
function enable() {
tooltip.opacity = 0;

if(Main.panel.statusArea && Main.panel.statusArea["appMenu"]) {
appMenu = Main.panel.statusArea["appMenu"];
} else if(Main.panel._appMenu) {
appMenu = Main.panel._appMenu;
} else if(Main.panel.statusArea["appMenu"]) {
appMenu = Main.panel.statusArea["appMenu"];
} else if(Main.panel._appMenu) {
appMenu = Main.panel._appMenu;
} else if(Main.panel.statusArea["appMenu"]) {
appMenu = Main.panel.statusArea["appMenu"];
} else {
appMenu = Main.panel.statusArea.appMenu;
}

focusCallbackID = Shell.WindowTracker.get_default().connect('notify::focus-app', onFocusChange);

wmCallbackIDs.push(global.window_manager.connect('maximize', updateAppMenu));
wmCallbackIDs.push(global.window_manager.connect('unmaximize', updateAppMenu));

// note: 'destroy' needs a delay for .list_windows() report correctly
wmCallbackIDs.push(global.window_manager.connect('destroy', function () {
Mainloop.idle_add(updateAppMenu);
}));

tooltipCallbackID = appMenu.actor.connect('notify::hover', onHover);
}

function disable() {
appMenu.actor.disconnect(tooltipCallbackID);

Shell.WindowTracker.get_default().disconnect(focusCallbackID);
focusCallbackID = 0;

for (let i = 0; i < wmCallbackIDs.length; ++i) {
global.window_manager.disconnect(wmCallbackIDs[i]);
}

wmCallbackIDs = [];

if(activeWindow) {
activeWindow.disconnect(awCallbackID);
awCallbackID = 0;
activeWindow = null;
}

if(tooltipDelayCallbackID) {
Mainloop.source_remove(tooltipDelayCallbackID);
tooltipDelayCallbackID = 0;
}

if(menuCallbackID) {
appMenu.menu.disconnect(menuCallbackID);
menuCallbackID = 0;
}

Main.uiGroup.remove_actor(tooltip);
}

23 changes: 12 additions & 11 deletions [email protected]/decoration.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function guessWindowXID(win) {
*
* **Caveat**: doesn't work with Ubuntu's Ambiance and Radiance window themes -
* my guess is they don't respect or implement this property.
*
*
* I don't know how to read the inital value, so I'm not sure how to resore it.
*
* @param {Meta.Window} win - window to set the HIDE_TITLEBAR_WHEN_MAXIMIZED property of.
Expand Down Expand Up @@ -144,7 +144,7 @@ function onWindowAdded(ws, win) {
if (win._pixelSaverOriginalState !== undefined) {
return false;
}

/* Newly-created windows are added to the workspace before
* the compositor knows about them: get_compositor_private() is null.
* Additionally things like .get_maximized() aren't properly done yet.
Expand All @@ -153,11 +153,11 @@ function onWindowAdded(ws, win) {
// FIXME: get hide-titlebar-when-maximized value
win._pixelSaverOriginalState = false;
LOG('onWindowAdded: ' + win.get_title() + ' initially hide title ? ' + win._pixelSaverOriginalState);

if(win._pixelSaverOriginalState === false) {
setHideTitlebar(win, true);
}

return false;
}

Expand All @@ -176,7 +176,7 @@ function onChangeNWorkspaces() {
let ws = workspaces[i];
ws.disconnect(ws._pixelSaverWindowAddedId);
}

workspaces = [];
i = global.screen.n_workspaces;
while (i--) {
Expand All @@ -188,7 +188,7 @@ function onChangeNWorkspaces() {
Mainloop.idle_add(function () { return onWindowAdded(ws, win); });
});
}

return false;
}

Expand All @@ -201,7 +201,7 @@ let changeWorkspaceID = 0;
function enable() {
/* Connect events */
changeWorkspaceID = global.screen.connect('notify::n-workspaces', onChangeNWorkspaces);

/* Go through already-maximised windows & undecorate.
* This needs a delay as the window list is not yet loaded
* when the extension is loaded.
Expand All @@ -221,7 +221,7 @@ function enable() {
}
onWindowAdded(null, win);
}

onChangeNWorkspaces();
return false;
});
Expand All @@ -232,15 +232,15 @@ function disable() {
global.window_manager.disconnect(changeWorkspaceID);
changeWorkspaceID = 0;
}

/* disconnect window-added from workspaces */
let i = workspaces.length;
while (i--) {
workspaces[i].disconnect(workspaces[i]._pixelSaverWindowAddedId);
delete workspaces[i]._pixelSaverWindowAddedId;
}
workspaces = [];

let winList = global.get_window_actors().map(function (w) { return w.meta_window; }),
i = winList.length;
while (i--) {
Expand All @@ -249,10 +249,11 @@ function disable() {
continue;
}
LOG('stopUndecorating: ' + win.title);

if (win._pixelSaverOriginalState === false) {
setHideTitlebar(win, false);
}
delete win._pixelSaverOriginalState;
}
}

45 changes: 45 additions & 0 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
/*global global, log */ // <-- jshint
/*jshint maxlen: 150 */
/* @overview
* Pixel Saver v1.0
* Amaury SECHET <[email protected]>
* Other contributors:
* - Amy Chan <[email protected]>
* Sept-- 2013.
*
* ## Help! It didn't work/I found a bug!
*
* This extension is based on work by Amy Chan, namely maximus[1] and Window Buttons[2].
*
* 1. Make sure you can *reproduce* the bug reliably.
* 2. Do 'Ctrl + F2' and 'lg' and see if there are any errors produced by Maximus,
* both in the 'Errors' window *and* the 'Extensions' > 'Maximus' > 'Show Errors'
* tab (the 'Show Errors' is in GNOME 3.4+ only I think).
* 3. Disable all your extensions except Maximus and see if you can still reproduce
* the bug. If so, mention this.
* 4. If you can't reproduce th bug with all extensions but Maximus disabled, then
* gradually enable your extensions one-by-one until you work out which one(s)
* together cause the bug, and mention these.
* 5. Open a new issue at [4].
* 6. Include how you can reproduce the bug and any relevant information from 2--4.
* 7. Also include:
* - your version of the extension (in metadata.json)
* - list of all your installed extensions (including disabled ones, as
* this is no guarantee they won't interfere with other extensions)
* - your version of GNOME-shell (gnome-shell --version).
* 8. I'll try get back to you with a fix.
* (Brownie points: open a terminal, do `gnome-shell --replace` and reproduce the
* bug. Include any errors that pop up in this terminal.)
*
* ## Note:
* It's actually possible to get the undecorate-on-maximise behaviour without
* needing this extension. See the link [5] and in particular, the bit on editing
* your metacity theme metacity-theme-3.xml. ("Method 2: editing the theme").
*
* ## References:
* [1]:https://launchpad.net/maximus
* [2]:https://extensions.gnome.org/extension/59/status-title-bar/
* [3]:https://bitbucket.org/mathematicalcoffee/window-options-gnome-shell-extension
* [4]:https://bitbucket.org/mathematicalcoffee/maximus-gnome-shell-extension/issues
* [5]:http://www.webupd8.org/2011/05/how-to-remove-maximized-windows.html
*
*/
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Decoration = Me.imports.decoration;
Expand All @@ -19,3 +63,4 @@ function disable() {
AppMenu.disable();
Decoration.disable();
}

13 changes: 12 additions & 1 deletion [email protected]/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
{"shell-version": ["3.8", "3.10", "3.12", "3.14"],"uuid": "[email protected]", "name": "Maximus Two", "description": "Removes the title bar on maximised windows.\n Based on Pixel Saver (use Window Buttons to get the buttons (you can configure them then)\n You should be albe to use the original Maximus extension if you have 3.4 or 3.6", "url": "https://github.com/wilfm/GnomeExtensionMaximusTwo", "version": 2}
{ "description": "Removes the title bar on maximised windows.\n Based on Pixel Saver (use Window Buttons to get the buttons (you can configure them then)\n You should be able to use the original Maximus extension if you have 3.4 or 3.6\nPlease report bugs on the github issues page: https://github.com/wilfm/GnomeExtensionMaximusTwo/issues\nNote you need xprop installed for this to work - see the github page for help with which package to install.",
"name": "Maximus Two",
"shell-version": [
"3.6",
"3.8",
"3.10",
"3.12"
],
"url": "https://github.com/wilfm/GnomeExtensionMaximusTwo",
"uuid": "[email protected]",
"version": 3
}
1 change: 1 addition & 0 deletions [email protected]/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ function getWindow() {

return null;
}

0 comments on commit e2572ca

Please sign in to comment.