diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-01-24 11:03:06 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-01-24 11:03:06 +0100 |
commit | b683ce2789d95b2e9f221e75adc30efd91cfb901 (patch) | |
tree | 7903b95887c3fbb995ec2e6a99b027053e617adf /src/utilities | |
parent | 73201cab74e84e5372b6c4a1f72f7e70df5c0d5a (diff) |
Imported Upstream version 0.5.7upstream/0.5.7
Diffstat (limited to 'src/utilities')
-rw-r--r-- | src/utilities/color.vala | 87 | ||||
-rw-r--r-- | src/utilities/config.vala | 62 | ||||
-rw-r--r-- | src/utilities/focusGrabber.vala | 120 |
3 files changed, 121 insertions, 148 deletions
diff --git a/src/utilities/color.vala b/src/utilities/color.vala index 836411e..bf60e3f 100644 --- a/src/utilities/color.vala +++ b/src/utilities/color.vala @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 2011 by Simon Schneegans This program is free software: you can redistribute it and/or modify it @@ -12,14 +12,14 @@ 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, see <http://www.gnu.org/licenses/>. +this program. If not, see <http://www.gnu.org/licenses/>. */ using GLib.Math; namespace GnomePie { -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// /// A Color class with full rgb/hsv support /// and some useful utility methods. ///////////////////////////////////////////////////////////////////////// @@ -35,15 +35,15 @@ public class Color: GLib.Object { private float _g; private float _b; private float _a; - + ///////////////////////////////////////////////////////////////////// /// Creates a white Color. ///////////////////////////////////////////////////////////////////// - + public Color() { Color.from_rgb(1.0f, 1.0f, 1.0f); } - + ///////////////////////////////////////////////////////////////////// /// Creates a solid color with the given RGB values. ///////////////////////////////////////////////////////////////////// @@ -51,47 +51,48 @@ public class Color: GLib.Object { public Color.from_rgb(float red, float green, float blue) { Color.from_rgba(red, green, blue, 1.0f); } - + ///////////////////////////////////////////////////////////////////// /// Creates a translucient color with the given RGBA values. ///////////////////////////////////////////////////////////////////// - + public Color.from_rgba(float red, float green, float blue, float alpha) { r = red; g = green; b = blue; a = alpha; } - + ///////////////////////////////////////////////////////////////////// /// Creates a color from the given Gdk.Color ///////////////////////////////////////////////////////////////////// - - public Color.from_gdk(Gdk.Color color) { - Color.from_rgb( - (float)color.red/65535.0f, - (float)color.green/65535.0f, - (float)color.blue/65535.0f + + public Color.from_gdk(Gdk.RGBA color) { + Color.from_rgba( + (float)color.red, + (float)color.green, + (float)color.blue, + (float)color.alpha ); } - + ///////////////////////////////////////////////////////////////////// /// Creates a color, parsed from a string, such as #22EE33 ///////////////////////////////////////////////////////////////////// - + public Color.from_string(string hex_string) { - Gdk.Color color; - Gdk.Color.parse(hex_string, out color); + var color = Gdk.RGBA(); + color.parse(hex_string); Color.from_gdk(color); } - + ///////////////////////////////////////////////////////////////////// /// Gets the main color from an Image. Code from Unity. ///////////////////////////////////////////////////////////////////// - + public Color.from_icon(Image icon) { unowned uchar[] data = icon.surface.get_data(); - + uint width = icon.surface.get_width(); uint height = icon.surface.get_height(); uint row_bytes = icon.surface.get_stride(); @@ -99,7 +100,7 @@ public class Color: GLib.Object { double total = 0.0; double rtotal = 0.0; double gtotal = 0.0; - double btotal = 0.0; + double btotal = 0.0; for (uint i = 0; i < width; ++i) { for (uint j = 0; j < height; ++j) { @@ -126,7 +127,7 @@ public class Color: GLib.Object { v = 1.0f; } - + ///////////////////////////////////////////////////////////////////// /// The reddish part of the color. ///////////////////////////////////////////////////////////////////// @@ -138,14 +139,14 @@ public class Color: GLib.Object { set { if (value > 1.0f) _r = 1.0f; else if (value < 0.0f) _r = 0.0f; - else _r = value; + else _r = value; } } - + ///////////////////////////////////////////////////////////////////// /// The greenish part of the color. ///////////////////////////////////////////////////////////////////// - + public float g { get { return _g; @@ -153,14 +154,14 @@ public class Color: GLib.Object { set { if (value > 1.0f) _g = 1.0f; else if (value < 0.0f) _g = 0.0f; - else _g = value; + else _g = value; } } - + ///////////////////////////////////////////////////////////////////// /// The blueish part of the color. ///////////////////////////////////////////////////////////////////// - + public float b { get { return _b; @@ -168,14 +169,14 @@ public class Color: GLib.Object { set { if (value > 1.0f) _b = 1.0f; else if (value < 0.0f) _b = 0.0f; - else _b = value; + else _b = value; } } - + ///////////////////////////////////////////////////////////////////// /// The transparency of the color. ///////////////////////////////////////////////////////////////////// - + public float a { get { return _a; @@ -183,14 +184,14 @@ public class Color: GLib.Object { set { if (value > 1.0f) _a = 1.0f; else if (value < 0.0f) _a = 0.0f; - else _a = value; + else _a = value; } } - + ///////////////////////////////////////////////////////////////////// /// The hue of the color. ///////////////////////////////////////////////////////////////////// - + public float h { get { if (s > 0.0f) { @@ -210,11 +211,11 @@ public class Color: GLib.Object { setHSV(value, s, v); } } - + ///////////////////////////////////////////////////////////////////// /// The saturation of the color. ///////////////////////////////////////////////////////////////////// - + public float s { get { if (v == 0.0f) return 0.0f; @@ -226,11 +227,11 @@ public class Color: GLib.Object { else setHSV(h, value, v); } } - + ///////////////////////////////////////////////////////////////////// /// The value of the color. ///////////////////////////////////////////////////////////////////// - + public float v { get { return fmaxf(fmaxf(r, g), b); @@ -241,16 +242,16 @@ public class Color: GLib.Object { else setHSV(h, s, value); } } - + ///////////////////////////////////////////////////////////////////// /// Inverts the color. ///////////////////////////////////////////////////////////////////// - + public void invert() { h += 180.0f; v = 1.0f - v; } - + ///////////////////////////////////////////////////////////////////// /// Private member, used to apply color changes. ///////////////////////////////////////////////////////////////////// diff --git a/src/utilities/config.vala b/src/utilities/config.vala index 1d8b714..2ec2788 100644 --- a/src/utilities/config.vala +++ b/src/utilities/config.vala @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 2011 by Simon Schneegans This program is free software: you can redistribute it and/or modify it @@ -12,12 +12,12 @@ 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, see <http://www.gnu.org/licenses/>. +this program. If not, see <http://www.gnu.org/licenses/>. */ namespace GnomePie { -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// /// A singleton class for storing global settings. These settings can /// be loaded from and saved to an XML file. ///////////////////////////////////////////////////////////////////////// @@ -29,11 +29,11 @@ public class Config : GLib.Object { ///////////////////////////////////////////////////////////////////// private static Config _instance = null; - + ///////////////////////////////////////////////////////////////////// /// Returns the singleton instance. ///////////////////////////////////////////////////////////////////// - + public static Config global { get { if (_instance == null) { @@ -46,7 +46,7 @@ public class Config : GLib.Object { _instance = value; } } - + ///////////////////////////////////////////////////////////////////// /// All settings variables. ///////////////////////////////////////////////////////////////////// @@ -54,16 +54,17 @@ public class Config : GLib.Object { public Theme theme { get; set; } public double refresh_rate { get; set; default = 60.0; } public double global_scale { get; set; default = 1.0; } + public int activation_range { get; set; default = 300; } public bool show_indicator { get; set; default = true; } public bool show_captions { get; set; default = true; } public bool auto_start { get; set; default = false; } public int showed_news { get; set; default = 0; } public Gee.ArrayList<Theme?> themes { get; private set; } - + ///////////////////////////////////////////////////////////////////// /// Saves all above variables to a file. ///////////////////////////////////////////////////////////////////// - + public void save() { var writer = new Xml.TextWriter.filename(Paths.settings); writer.start_document("1.0"); @@ -71,28 +72,29 @@ public class Config : GLib.Object { writer.write_attribute("theme", theme.name); writer.write_attribute("refresh_rate", refresh_rate.to_string()); writer.write_attribute("global_scale", global_scale.to_string()); + writer.write_attribute("activation_range", activation_range.to_string()); writer.write_attribute("show_indicator", show_indicator ? "true" : "false"); writer.write_attribute("show_captions", show_captions ? "true" : "false"); writer.write_attribute("showed_news", showed_news.to_string()); writer.end_element(); writer.end_document(); } - + ///////////////////////////////////////////////////////////////////// /// Loads all settings variables from a file. ///////////////////////////////////////////////////////////////////// - + private void load() { - + // check for auto_start filename this.auto_start = FileUtils.test(Paths.autostart, FileTest.EXISTS); - + // parse the settings file Xml.Parser.init(); Xml.Doc* settingsXML = Xml.Parser.parse_file(Paths.settings); bool error_occrured = false; string theme_name = ""; - + if (settingsXML != null) { Xml.Node* root = settingsXML->get_root_element(); @@ -101,7 +103,7 @@ public class Config : GLib.Object { for (Xml.Attr* attribute = root->properties; attribute != null; attribute = attribute->next) { string attr_name = attribute->name.down(); string attr_content = attribute->children->content; - + switch (attr_name) { case "theme": theme_name = attr_content; @@ -113,6 +115,10 @@ public class Config : GLib.Object { global_scale = double.parse(attr_content); global_scale.clamp(0.5, 2.0); break; + case "activation_range": + activation_range = int.parse(attr_content); + activation_range.clamp(100, 2000); + break; case "show_indicator": show_indicator = bool.parse(attr_content); break; @@ -127,45 +133,45 @@ public class Config : GLib.Object { break; } } - + Xml.Parser.cleanup(); - + } else { warning("Error loading settings: gnome-pie.conf is empty! Using defaults..."); error_occrured = true; } - + delete settingsXML; - + } else { warning("Error loading settings: gnome-pie.conf not found! Using defaults..."); error_occrured = true; } - + load_themes(theme_name); if (error_occrured) save(); } - + ///////////////////////////////////////////////////////////////////// /// Registers all themes in the user's and in the global /// theme directory. ///////////////////////////////////////////////////////////////////// - + public void load_themes(string current) { themes = new Gee.ArrayList<Theme?>(); try { string name; - + // load global themes var d = Dir.open(Paths.global_themes); while ((name = d.read_name()) != null) { var theme = new Theme(Paths.global_themes + "/" + name); - + if (theme.load()) themes.add(theme); } - + // load local themes d = Dir.open(Paths.local_themes); while ((name = d.read_name()) != null) { @@ -173,11 +179,11 @@ public class Config : GLib.Object { if (theme.load()) themes.add(theme); } - + } catch (Error e) { warning (e.message); - } - + } + if (themes.size > 0) { if (current == "") { current = "Unity"; @@ -197,7 +203,7 @@ public class Config : GLib.Object { } else error("No theme found!"); } - + } } diff --git a/src/utilities/focusGrabber.vala b/src/utilities/focusGrabber.vala index e5900d6..b551def 100644 --- a/src/utilities/focusGrabber.vala +++ b/src/utilities/focusGrabber.vala @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 2011 by Simon Schneegans This program is free software: you can redistribute it and/or modify it @@ -12,12 +12,12 @@ 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, see <http://www.gnu.org/licenses/>. +this program. If not, see <http://www.gnu.org/licenses/>. */ namespace GnomePie { -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// /// Some helper methods which focus the input on a given Gtk.Window. ///////////////////////////////////////////////////////////////////////// @@ -27,7 +27,7 @@ public class FocusGrabber : GLib.Object { /// Utilities for grabbing focus. /// Code roughly from Gnome-Do/Synapse. ///////////////////////////////////////////////////////////////////// - + public static void grab(Gdk.Window window, bool keyboard = true, bool pointer = true, bool owner_events = true) { if (keyboard || pointer) { window.raise(); @@ -42,90 +42,56 @@ public class FocusGrabber : GLib.Object { } } } - + ///////////////////////////////////////////////////////////////////// /// Code roughly from Gnome-Do/Synapse. ///////////////////////////////////////////////////////////////////// - + public static void ungrab(bool keyboard = true, bool pointer = true) { - #if HAVE_GTK_3 - - var display = Gdk.Display.get_default(); - var manager = display.get_device_manager(); - - #if VALA_0_16 || VALA_0_17 - GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); - #else - unowned GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); - #endif - - foreach(var device in list) { - if ((device.input_source == Gdk.InputSource.KEYBOARD && keyboard) - || (device.input_source != Gdk.InputSource.KEYBOARD && pointer)) - - device.ungrab(Gdk.CURRENT_TIME); - } - - #else - - if (pointer) Gdk.pointer_ungrab(Gdk.CURRENT_TIME); - if (keyboard) Gdk.keyboard_ungrab(Gdk.CURRENT_TIME); - - #endif + var display = Gdk.Display.get_default(); + var manager = display.get_device_manager(); + + GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); + + foreach(var device in list) { + if ((device.input_source == Gdk.InputSource.KEYBOARD && keyboard) + || (device.input_source != Gdk.InputSource.KEYBOARD && pointer)) + + device.ungrab(Gdk.CURRENT_TIME); + } } - + ///////////////////////////////////////////////////////////////////// /// Code roughly from Gnome-Do/Synapse. ///////////////////////////////////////////////////////////////////// - + private static bool try_grab_window(Gdk.Window window, bool keyboard, bool pointer, bool owner_events) { - #if HAVE_GTK_3 - - var display = Gdk.Display.get_default(); - var manager = display.get_device_manager(); - - bool grabbed_all = true; - - #if VALA_0_16 - GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); - #else - unowned GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); - #endif - - foreach(var device in list) { - if ((device.input_source == Gdk.InputSource.KEYBOARD && keyboard) - || (device.input_source != Gdk.InputSource.KEYBOARD && pointer)) { - - var status = device.grab(window, Gdk.GrabOwnership.APPLICATION, owner_events, - Gdk.EventMask.ALL_EVENTS_MASK, null, Gdk.CURRENT_TIME); - - if (status != Gdk.GrabStatus.SUCCESS) - grabbed_all = false; - } - } - - if (grabbed_all) - return true; - - ungrab(keyboard, pointer); - - #else - - if (!pointer || Gdk.pointer_grab(window, owner_events, Gdk.EventMask.BUTTON_PRESS_MASK | - Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK, - null, null, Gdk.CURRENT_TIME) == Gdk.GrabStatus.SUCCESS) { - - if (!keyboard || Gdk.keyboard_grab(window, owner_events, Gdk.CURRENT_TIME) == Gdk.GrabStatus.SUCCESS) { - return true; - } else if (pointer) { - ungrab(false, true); - return false; - } + var display = Gdk.Display.get_default(); + var manager = display.get_device_manager(); + + bool grabbed_all = true; + + GLib.List<weak Gdk.Device?> list = manager.list_devices(Gdk.DeviceType.MASTER); + + foreach(var device in list) { + if ((device.input_source == Gdk.InputSource.KEYBOARD && keyboard) + || (device.input_source != Gdk.InputSource.KEYBOARD && pointer)) { + + var status = device.grab(window, Gdk.GrabOwnership.APPLICATION, owner_events, + Gdk.EventMask.ALL_EVENTS_MASK, null, Gdk.CURRENT_TIME); + + if (status != Gdk.GrabStatus.SUCCESS) + grabbed_all = false; } - #endif - + } + + if (grabbed_all) + return true; + + ungrab(keyboard, pointer); + return false; - } + } } } |