[gnome-shell-extensions] screenshot-window-sizer: New extension
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions] screenshot-window-sizer: New extension
- Date: Wed, 17 Sep 2014 05:17:15 +0000 (UTC)
commit 1d5ab0f0de55ab2a8c954feb1355ad30797d8177
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Sep 6 22:44:44 2014 +0200
screenshot-window-sizer: New extension
Originally from hughsie's github[0], but way too useful to leave
in a 3rd party repo :-)
[0] https://github.com/hughsie/gnome-shell-extension-screenshot-window-sizer
https://bugzilla.gnome.org/show_bug.cgi?id=736470
configure.ac | 5 +-
extensions/screenshot-window-sizer/Makefile.am | 4 +
extensions/screenshot-window-sizer/extension.js | 147 ++++++++++++++++++++
.../screenshot-window-sizer/metadata.json.in | 10 ++
...tensions.screenshot-window-sizer.gschema.xml.in | 10 ++
extensions/screenshot-window-sizer/stylesheet.css | 8 +
po/POTFILES.in | 1 +
7 files changed, 183 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 53d1f87..4283bd9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,7 +28,7 @@ AC_SUBST([SHELL_VERSION])
dnl keep this in alphabetic order
CLASSIC_EXTENSIONS="apps-menu places-menu alternate-tab launch-new-instance window-list"
-DEFAULT_EXTENSIONS="$CLASSIC_EXTENSIONS drive-menu windowsNavigator workspace-indicator"
+DEFAULT_EXTENSIONS="$CLASSIC_EXTENSIONS drive-menu screenshot-window-sizer windowsNavigator
workspace-indicator"
ALL_EXTENSIONS="$DEFAULT_EXTENSIONS auto-move-windows example native-window-placement systemMonitor
user-theme"
AC_SUBST(CLASSIC_EXTENSIONS, [$CLASSIC_EXTENSIONS])
AC_SUBST(ALL_EXTENSIONS, [$ALL_EXTENSIONS])
@@ -66,7 +66,7 @@ for e in $enable_extensions; do
[AC_MSG_WARN([libgtop-2.0 not found, disabling systemMonitor])])
;;
dnl keep this in alphabetic order
-
alternate-tab|apps-menu|auto-move-windows|drive-menu|example|launch-new-instance|native-window-placement|places-menu|user-theme|window-list|windowsNavigator|workspace-indicator)
+
alternate-tab|apps-menu|auto-move-windows|drive-menu|example|launch-new-instance|native-window-placement|places-menu|screenshot-window-sizer|user-theme|window-list|windowsNavigator|workspace-indicator)
ENABLED_EXTENSIONS="$ENABLED_EXTENSIONS $e"
;;
*)
@@ -87,6 +87,7 @@ AC_CONFIG_FILES([
extensions/launch-new-instance/Makefile
extensions/native-window-placement/Makefile
extensions/places-menu/Makefile
+ extensions/screenshot-window-sizer/Makefile
extensions/systemMonitor/Makefile
extensions/user-theme/Makefile
extensions/window-list/Makefile
diff --git a/extensions/screenshot-window-sizer/Makefile.am b/extensions/screenshot-window-sizer/Makefile.am
new file mode 100644
index 0000000..a3e1dfd
--- /dev/null
+++ b/extensions/screenshot-window-sizer/Makefile.am
@@ -0,0 +1,4 @@
+EXTENSION_ID = screenshot-window-sizer
+
+include ../../extension.mk
+include ../../settings.mk
diff --git a/extensions/screenshot-window-sizer/extension.js b/extensions/screenshot-window-sizer/extension.js
new file mode 100644
index 0000000..1e573ea
--- /dev/null
+++ b/extensions/screenshot-window-sizer/extension.js
@@ -0,0 +1,147 @@
+/* Screenshot Window Sizer for Gnome Shell
+ *
+ * Copyright (c) 2013 Owen Taylor <otaylor redhat com>
+ * Copyright (c) 2013 Richard Hughes <richard hughsie com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+const Gio = imports.gi.Gio;
+const Meta = imports.gi.Meta;
+const Shell = imports.gi.Shell;
+const St = imports.gi.St;
+
+const Main = imports.ui.main;
+const Tweener = imports.ui.tweener;
+
+const ExtensionUtils = imports.misc.extensionUtils;
+const Me = ExtensionUtils.getCurrentExtension();
+const Convenience = Me.imports.convenience;
+
+const MESSAGE_FADE_TIME = 2;
+
+let text, button;
+
+function hideMessage() {
+ text.destroy();
+ text = null;
+}
+
+function flashMessage(message) {
+ if (!text) {
+ text = new St.Label({ style_class: 'screenshot-sizer-message' });
+ Main.uiGroup.add_actor(text);
+ }
+
+ Tweener.removeTweens(text);
+ text.text = message;
+
+ text.opacity = 255;
+
+ let monitor = Main.layoutManager.primaryMonitor;
+ text.set_position(monitor.x + Math.floor(monitor.width / 2 - text.width / 2),
+ monitor.y + Math.floor(monitor.height / 2 - text.height / 2));
+
+ Tweener.addTween(text,
+ { opacity: 0,
+ time: MESSAGE_FADE_TIME,
+ transition: 'easeOutQuad',
+ onComplete: hideMessage });
+}
+
+let SIZES = [
+ [624, 351],
+ [800, 450],
+ [1024, 576],
+ [1200, 675],
+ [1600, 900]
+];
+
+function cycleScreenshotSizes(display, screen, window, binding) {
+ // Probably this isn't useful with 5 sizes, but you can decrease instead
+ // of increase by holding down shift.
+ let modifiers = binding.get_modifiers();
+ let backwards = (modifiers & Meta.VirtualModifier.SHIFT_MASK) != 0;
+
+ // Unmaximize first
+ if (window.maximized_horizontally || window.maximizedVertically)
+ window.unmaximize(Meta.MaximizeFlags.HORIZONTAL | Meta.MaximizeFlags.VERTICAL);
+
+ let workArea = window.get_work_area_current_monitor();
+ let outerRect = window.get_outer_rect();
+
+ // Find the nearest 16:9 size for the current window size
+ let nearestIndex;
+ let nearestError;
+
+ for (let i = 0; i < SIZES.length; i++) {
+ let [width, height] = SIZES[i];
+
+ // ignore sizes bigger than the workArea
+ if (width > workArea.width || height > workArea.height)
+ continue;
+
+ // get the best initial window size
+ let error = Math.abs(width - outerRect.width) + Math.abs(height - outerRect.height);
+ if (nearestIndex == null || error < nearestError) {
+ nearestIndex = i;
+ nearestError = error;
+ }
+ }
+
+ // get the next size up or down from ideal
+ let newIndex = (nearestIndex + (backwards ? -1 : 1)) % SIZES.length;
+ let newWidth, newHeight;
+ [newWidth, newHeight] = SIZES[newIndex];
+ if (newWidth > workArea.width || newHeight > workArea.height)
+ [newWidth, newHeight] = SIZES[0];
+
+ // Push the window onscreen if it would be resized offscreen
+ let newX = outerRect.x;
+ let newY = outerRect.y;
+ if (newX + newWidth > workArea.x + workArea.width)
+ newX = Math.max(workArea.x + workArea.width - newWidth);
+ if (newY + newHeight > workArea.y + workArea.height)
+ newY = Math.max(workArea.y + workArea.height - newHeight);
+
+ window.move_resize_frame(true, newX, newY, newWidth, newHeight);
+
+ let newOuterRect = window.get_outer_rect();
+ let message = newOuterRect.width + 'x' + newOuterRect.height;
+
+ // The new size might have been constrained by geometry hints (e.g. for
+ // a terminal) - in that case, include the actual ratio to the message
+ // we flash
+ let actualNumerator = (newOuterRect.width / newOuterRect.height) * 9;
+ if (Math.abs(actualNumerator - 16) > 0.01)
+ message += ' (%.2f:9)'.format(actualNumerator);
+
+ flashMessage(message);
+}
+
+function init() {
+}
+
+function enable() {
+ Main.wm.addKeybinding('cycle-screenshot-sizes',
+ Convenience.getSettings(),
+ Meta.KeyBindingFlags.PER_WINDOW | Meta.KeyBindingFlags.REVERSES,
+ Shell.KeyBindingMode.NORMAL,
+ cycleScreenshotSizes);
+}
+
+function disable() {
+ Main.wm.removeKeybinding('cycle-screenshot-sizes');
+}
diff --git a/extensions/screenshot-window-sizer/metadata.json.in
b/extensions/screenshot-window-sizer/metadata.json.in
new file mode 100644
index 0000000..185e63f
--- /dev/null
+++ b/extensions/screenshot-window-sizer/metadata.json.in
@@ -0,0 +1,10 @@
+{
+"extension-id": "@extension_id@",
+"uuid": "@uuid@",
+"settings-schema": "@gschemaname@",
+"gettext-domain": "@gettext_domain@",
+"name": "Screenshot Window Sizer",
+"description": "Resize windows for GNOME Software screenshots",
+"shell-version": [ "@shell_current@" ],
+"url": "@url@"
+}
diff --git
a/extensions/screenshot-window-sizer/org.gnome.shell.extensions.screenshot-window-sizer.gschema.xml.in
b/extensions/screenshot-window-sizer/org.gnome.shell.extensions.screenshot-window-sizer.gschema.xml.in
new file mode 100644
index 0000000..f1739a9
--- /dev/null
+++ b/extensions/screenshot-window-sizer/org.gnome.shell.extensions.screenshot-window-sizer.gschema.xml.in
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+ <schema id="org.gnome.shell.extensions.screenshot-window-sizer"
+ path="/org/gnome/shell/extensions/screenshot-window-sizer/">
+ <key type="as" name="cycle-screenshot-sizes">
+ <default><![CDATA[['<Alt><Control>s']]]></default>
+ <_summary>Cycle Screenshot Sizes</_summary>
+ </key>
+ </schema>
+</schemalist>
diff --git a/extensions/screenshot-window-sizer/stylesheet.css
b/extensions/screenshot-window-sizer/stylesheet.css
new file mode 100644
index 0000000..b2edab2
--- /dev/null
+++ b/extensions/screenshot-window-sizer/stylesheet.css
@@ -0,0 +1,8 @@
+.screenshot-sizer-message {
+ font-size: 36px;
+ font-weight: bold;
+ color: #ffffff;
+ background-color: rgba(10,10,10,0.7);
+ border-radius: 5px;
+ padding: .5em;
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 89bd3ee..1756bd1 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -15,6 +15,7 @@ extensions/native-window-placement/extension.js
extensions/native-window-placement/org.gnome.shell.extensions.native-window-placement.gschema.xml.in
extensions/places-menu/extension.js
extensions/places-menu/placeDisplay.js
+extensions/screenshot-window-sizer/org.gnome.shell.extensions.screenshot-window-sizer.gschema.xml.in
extensions/systemMonitor/extension.js
extensions/user-theme/extension.js
extensions/user-theme/org.gnome.shell.extensions.user-theme.gschema.xml.in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]