summaryrefslogtreecommitdiff
path: root/unity-shared
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2014-01-21 18:08:18 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2014-01-21 18:08:18 +0100
commit4961ab317da7d203d8abb160a5439bced78921a8 (patch)
tree83773c3a11159aa30c84c4d97d73df28988bb83d /unity-shared
parent7e674821d242f088ddb2087c74d1f873c92166bf (diff)
parentfa99f5f8e832020c7cc83497df069320f542171b (diff)
Merging with trunk
(bzr r3566.5.241)
Diffstat (limited to 'unity-shared')
-rw-r--r--unity-shared/CMakeLists.txt1
-rw-r--r--unity-shared/DesktopApplicationManager.h2
-rw-r--r--unity-shared/EMConverter.cpp105
-rw-r--r--unity-shared/EMConverter.h56
-rw-r--r--unity-shared/PluginAdapter.cpp16
-rw-r--r--unity-shared/PluginAdapter.h2
-rw-r--r--unity-shared/StandaloneWindowManager.cpp35
-rw-r--r--unity-shared/StandaloneWindowManager.h6
-rw-r--r--unity-shared/WindowManager.h2
-rw-r--r--unity-shared/ZeitgeistUtils.h55
10 files changed, 222 insertions, 58 deletions
diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt
index 63735654c..bb2e6e179 100644
--- a/unity-shared/CMakeLists.txt
+++ b/unity-shared/CMakeLists.txt
@@ -27,6 +27,7 @@ set (UNITY_SHARED_SOURCES
DefaultThumbnailProvider.cpp
DeltaRestrainment.cpp
DesktopApplicationManager.cpp
+ EMConverter.cpp
GnomeFileManager.cpp
FontSettings.cpp
GraphicsUtils.cpp
diff --git a/unity-shared/DesktopApplicationManager.h b/unity-shared/DesktopApplicationManager.h
index d398983aa..8bd7f1105 100644
--- a/unity-shared/DesktopApplicationManager.h
+++ b/unity-shared/DesktopApplicationManager.h
@@ -20,11 +20,11 @@
#ifndef UNITYSHARED_DESKTOP_APPLICATION_MANAGER_H
#define UNITYSHARED_DESKTOP_APPLICATION_MANAGER_H
+#include <zeitgeist.h>
#include <UnityCore/GLibWrapper.h>
#include <UnityCore/GLibSignal.h>
#include "unity-shared/ApplicationManager.h"
-#include "unity-shared/ZeitgeistUtils.h"
namespace unity
{
diff --git a/unity-shared/EMConverter.cpp b/unity-shared/EMConverter.cpp
new file mode 100644
index 000000000..fa67834e8
--- /dev/null
+++ b/unity-shared/EMConverter.cpp
@@ -0,0 +1,105 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2014 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
+ */
+
+#include "EMConverter.h"
+
+namespace unity
+{
+
+double const BASE_DPI = 96.0;
+double const DEFAULT_PPE = 10.0;
+double const PIXELS_PER_INCH = 72.0;
+
+EMConverter::EMConverter(int font_size, double dpi)
+ : pixels_per_em_(DEFAULT_PPE)
+ , base_pixels_per_em_(DEFAULT_PPE)
+ , dpi_(dpi)
+ , font_size_(font_size)
+{
+ UpdatePixelsPerEM();
+ UpdateBasePixelsPerEM();
+}
+
+void EMConverter::UpdatePixelsPerEM()
+{
+ pixels_per_em_ = font_size_ * dpi_ / PIXELS_PER_INCH;
+
+ if (pixels_per_em_ == 0)
+ pixels_per_em_ = DEFAULT_PPE;
+}
+
+void EMConverter::UpdateBasePixelsPerEM()
+{
+ base_pixels_per_em_ = font_size_ * BASE_DPI / PIXELS_PER_INCH;
+
+ if (base_pixels_per_em_ == 0)
+ base_pixels_per_em_ = DEFAULT_PPE;
+}
+
+void EMConverter::SetFontSize(int font_size)
+{
+ if (font_size != font_size_)
+ {
+ font_size_ = font_size;
+ UpdatePixelsPerEM();
+ UpdateBasePixelsPerEM();
+ }
+}
+
+void EMConverter::SetDPI(double dpi)
+{
+ if (dpi != dpi_)
+ {
+ dpi_ = dpi;
+ UpdatePixelsPerEM();
+ }
+}
+
+int EMConverter::GetFontSize() const
+{
+ return font_size_;
+}
+
+double EMConverter::GetDPI() const
+{
+ return dpi_;
+}
+
+int EMConverter::EMToPixels(double em) const
+{
+ return (em * pixels_per_em_);
+}
+
+double EMConverter::PixelsToBaseEM(int pixels) const
+{
+ return (pixels / base_pixels_per_em_);
+}
+
+int EMConverter::ConvertPixels(int pixels) const
+{
+ double pixels_em = PixelsToBaseEM(pixels);
+ return EMToPixels(pixels_em);
+}
+
+double EMConverter::DPIScale() const
+{
+ return dpi_ / BASE_DPI;
+}
+
+} // namespace unity
diff --git a/unity-shared/EMConverter.h b/unity-shared/EMConverter.h
new file mode 100644
index 000000000..739ce713a
--- /dev/null
+++ b/unity-shared/EMConverter.h
@@ -0,0 +1,56 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2014 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
+ */
+
+#ifndef EM_CONVERTER_H
+#define EM_CONVERTER_H
+
+namespace unity
+{
+
+class EMConverter
+{
+public:
+ EMConverter(int font_size, double dpi = 96.0);
+
+ void SetFontSize(int font_size);
+ void SetDPI(double dpi);
+
+ int GetFontSize() const;
+ double GetDPI() const;
+
+ int ConvertPixels(int pixels) const;
+ double DPIScale() const;
+
+private:
+ void UpdatePixelsPerEM();
+ void UpdateBasePixelsPerEM();
+
+ int EMToPixels(double em) const;
+ double PixelsToBaseEM(int pixels) const;
+
+ double pixels_per_em_;
+ double base_pixels_per_em_;
+
+ double dpi_;
+ int font_size_;
+};
+
+} // namespace unity
+
+#endif // EM_CONVERTER_H
diff --git a/unity-shared/PluginAdapter.cpp b/unity-shared/PluginAdapter.cpp
index 195a22c47..ef76a4644 100644
--- a/unity-shared/PluginAdapter.cpp
+++ b/unity-shared/PluginAdapter.cpp
@@ -472,6 +472,22 @@ bool PluginAdapter::IsWindowMaximized(Window window_id) const
return false;
}
+bool PluginAdapter::IsWindowVerticallyMaximized(Window window_id) const
+{
+ if (CompWindow* window = m_Screen->findWindow(window_id))
+ return (window->state() & CompWindowStateMaximizedVertMask);
+
+ return false;
+}
+
+bool PluginAdapter::IsWindowHorizontallyMaximized(Window window_id) const
+{
+ if (CompWindow* window = m_Screen->findWindow(window_id))
+ return (window->state() & CompWindowStateMaximizedHorzMask);
+
+ return false;
+}
+
bool PluginAdapter::HasWindowDecorations(Window window_id) const
{
return compiz_utils::IsWindowFullyDecorable(m_Screen->findWindow(window_id));
diff --git a/unity-shared/PluginAdapter.h b/unity-shared/PluginAdapter.h
index bb04827e4..2ae68d0d1 100644
--- a/unity-shared/PluginAdapter.h
+++ b/unity-shared/PluginAdapter.h
@@ -119,6 +119,8 @@ public:
// WindowManager implementation
bool IsWindowMaximized(Window window_id) const;
+ bool IsWindowVerticallyMaximized(Window window_id) const;
+ bool IsWindowHorizontallyMaximized(Window window_id) const;
bool IsWindowDecorated(Window window_id) const;
bool IsWindowOnCurrentDesktop(Window window_id) const;
bool IsWindowObscured(Window window_id) const;
diff --git a/unity-shared/StandaloneWindowManager.cpp b/unity-shared/StandaloneWindowManager.cpp
index 8a7cf9339..beb7e0263 100644
--- a/unity-shared/StandaloneWindowManager.cpp
+++ b/unity-shared/StandaloneWindowManager.cpp
@@ -42,7 +42,8 @@ StandaloneWindow::StandaloneWindow(Window xid)
, active(false)
, mapped(true)
, visible(true)
- , maximized(false)
+ , v_maximized(false)
+ , h_maximized(false)
, minimized(false)
, decorated(true)
, has_decorations(true)
@@ -66,6 +67,20 @@ StandaloneWindow::StandaloneWindow(Window xid)
return false;
});
+
+ maximized.SetGetterFunction([this] { return v_maximized && h_maximized; });
+ maximized.SetSetterFunction([this] (bool value) {
+ if (maximized() == value)
+ return false;
+
+ v_maximized = value;
+ h_maximized = value;
+ decorated = !value;
+ return true;
+ });
+
+ v_maximized.changed.connect([this] (bool value) { maximized.changed.emit(maximized()); });
+ h_maximized.changed.connect([this] (bool value) { maximized.changed.emit(maximized()); });
}
WindowManagerPtr create_window_manager()
@@ -130,6 +145,24 @@ bool StandaloneWindowManager::IsWindowMaximized(Window window_id) const
return false;
}
+bool StandaloneWindowManager::IsWindowVerticallyMaximized(Window window_id) const
+{
+ auto window = GetWindowByXid(window_id);
+ if (window)
+ return window->v_maximized;
+
+ return false;
+}
+
+bool StandaloneWindowManager::IsWindowHorizontallyMaximized(Window window_id) const
+{
+ auto window = GetWindowByXid(window_id);
+ if (window)
+ return window->h_maximized;
+
+ return false;
+}
+
bool StandaloneWindowManager::IsWindowDecorated(Window window_id) const
{
auto window = GetWindowByXid(window_id);
diff --git a/unity-shared/StandaloneWindowManager.h b/unity-shared/StandaloneWindowManager.h
index 7256e5213..152617da3 100644
--- a/unity-shared/StandaloneWindowManager.h
+++ b/unity-shared/StandaloneWindowManager.h
@@ -48,7 +48,9 @@ public:
nux::Property<bool> active;
nux::Property<bool> mapped;
nux::Property<bool> visible;
- nux::Property<bool> maximized;
+ nux::RWProperty<bool> maximized;
+ nux::Property<bool> v_maximized;
+ nux::Property<bool> h_maximized;
nux::Property<bool> minimized;
nux::Property<bool> decorated;
nux::Property<bool> has_decorations;
@@ -72,6 +74,8 @@ public:
virtual bool IsTopWindowFullscreenOnMonitorWithMouse() const override;
virtual bool IsWindowMaximized(Window window_id) const;
+ virtual bool IsWindowVerticallyMaximized(Window window_id) const;
+ virtual bool IsWindowHorizontallyMaximized(Window window_id) const;
virtual bool IsWindowDecorated(Window window_id) const;
virtual bool IsWindowOnCurrentDesktop(Window window_id) const;
virtual bool IsWindowObscured(Window window_id) const;
diff --git a/unity-shared/WindowManager.h b/unity-shared/WindowManager.h
index 82d9691d7..65239e64f 100644
--- a/unity-shared/WindowManager.h
+++ b/unity-shared/WindowManager.h
@@ -80,6 +80,8 @@ public:
virtual bool IsTopWindowFullscreenOnMonitorWithMouse() const = 0;
virtual bool IsWindowMaximized(Window window_id) const = 0;
+ virtual bool IsWindowVerticallyMaximized(Window window_id) const = 0;
+ virtual bool IsWindowHorizontallyMaximized(Window window_id) const = 0;
virtual bool IsWindowDecorated(Window window_id) const = 0;
virtual bool IsWindowOnCurrentDesktop(Window window_id) const = 0;
virtual bool IsWindowObscured(Window window_id) const = 0;
diff --git a/unity-shared/ZeitgeistUtils.h b/unity-shared/ZeitgeistUtils.h
deleted file mode 100644
index 823978baa..000000000
--- a/unity-shared/ZeitgeistUtils.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
-/*
- * Copyright (C) 2013 Canonical Ltd
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as
- * published by the Free Software Foundation.
- *
- * 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, see <http://www.gnu.org/licenses/>.
- *
- * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
- */
-
-#ifndef UNITY_ZEITGEIST_UTILS
-#define UNITY_ZEITGEIST_UTILS
-
-#include <zeitgeist.h>
-
-/* Unfortunately valac-generated zeitgeist library contains invalid definitions
- * that makes impossible for us to compile with -Werror -Wall, so we need to
- * workaround them.
- * Unfortunately using #pragma doesn't help much here as we can't limit the
- * errors to the header inclusion only, so it's better to use this way in order
- * to be able to include zeitgeist in multiple places without ignoring warnings.
- */
-
-static ZeitgeistEvent* zeitgeist_event_constructv_full(GType object_type, const gchar* interpretation, const gchar* manifestation, const gchar* actor, const gchar* origin, va_list _vala_va_list)
-{
- return nullptr;
-}
-
-namespace unity
-{
-namespace zeitgeist
-{
-namespace workaround
-{
-namespace
-{
-void ___dummy_function()
-{
- (void) zeitgeist_event_constructv_full;
-}
-} // anonymous namespace
-} // workaround namespace
-} // zeitgeist namespace
-} // unity namespace
-
-#endif // UNITY_ZEITGEIST_UTILS \ No newline at end of file