summaryrefslogtreecommitdiff
diff options
-rw-r--r--dash/DashController.cpp70
-rw-r--r--dash/DashController.h10
-rw-r--r--tests/autopilot/unity/emulators/dash.py10
-rw-r--r--tests/autopilot/unity/tests/test_dash.py9
4 files changed, 98 insertions, 1 deletions
diff --git a/dash/DashController.cpp b/dash/DashController.cpp
index 8593d7a20..a419bb7f6 100644
--- a/dash/DashController.cpp
+++ b/dash/DashController.cpp
@@ -20,6 +20,7 @@
#include <NuxCore/Logger.h>
#include <Nux/HLayout.h>
+#include <UnityCore/GLibWrapper.h>
#include "unity-shared/UnitySettings.h"
#include "unity-shared/PanelStyle.h"
@@ -38,8 +39,22 @@ namespace
{
nux::logging::Logger logger("unity.dash.controller");
const unsigned int PRELOAD_TIMEOUT_LENGTH = 40;
+
+const std::string DBUS_PATH = "/com/canonical/Unity/Dash";
+const std::string DBUS_INTROSPECTION =\
+ "<node>"
+ " <interface name='com.canonical.Unity.Dash'>"
+ ""
+ " <method name='HideDash'>"
+ " </method>"
+ ""
+ " </interface>"
+ "</node>";
}
+GDBusInterfaceVTable Controller::interface_vtable =
+ { Controller::OnDBusMethodCall, NULL, NULL};
+
Controller::Controller()
: launcher_width(64)
, use_primary(false)
@@ -49,6 +64,7 @@ Controller::Controller()
, view_(nullptr)
, ensure_timeout_(PRELOAD_TIMEOUT_LENGTH)
, timeline_animator_(90)
+ , dbus_connect_cancellable_(g_cancellable_new())
{
SetupRelayoutCallbacks();
RegisterUBusInterests();
@@ -70,6 +86,13 @@ Controller::Controller()
auto spread_cb = sigc::bind(sigc::mem_fun(this, &Controller::HideDash), true);
PluginAdapter::Default()->initiate_spread.connect(spread_cb);
+
+ g_bus_get (G_BUS_TYPE_SESSION, dbus_connect_cancellable_, OnBusAcquired, this);
+}
+
+Controller::~Controller()
+{
+ g_cancellable_cancel(dbus_connect_cancellable_);
}
void Controller::SetupWindow()
@@ -377,6 +400,53 @@ void Controller::AddProperties(GVariantBuilder* builder)
.add("monitor", monitor_);
}
+void Controller::OnBusAcquired(GObject *obj, GAsyncResult *result, gpointer user_data)
+{
+ glib::Error error;
+ glib::Object<GDBusConnection> connection(g_bus_get_finish (result, &error));
+
+ if (!connection || error)
+ {
+ LOG_WARNING(logger) << "Failed to connect to DBus:" << error;
+ }
+ else
+ {
+ GDBusNodeInfo* introspection_data = g_dbus_node_info_new_for_xml(DBUS_INTROSPECTION.c_str(), nullptr);
+ unsigned int reg_id;
+
+ if (!introspection_data)
+ {
+ LOG_WARNING(logger) << "No introspection data loaded.";
+ return;
+ }
+
+ reg_id = g_dbus_connection_register_object(connection, DBUS_PATH.c_str(),
+ introspection_data->interfaces[0],
+ &interface_vtable, user_data,
+ nullptr, nullptr);
+ if (!reg_id)
+ {
+ LOG_WARNING(logger) << "Object registration failed. Dash DBus interface not available.";
+ }
+
+ g_dbus_node_info_unref(introspection_data);
+ }
+}
+
+void Controller::OnDBusMethodCall(GDBusConnection* connection, const gchar* sender,
+ const gchar* object_path, const gchar* interface_name,
+ const gchar* method_name, GVariant* parameters,
+ GDBusMethodInvocation* invocation, gpointer user_data)
+{
+ if (g_strcmp0(method_name, "HideDash") == 0)
+ {
+ auto self = static_cast<Controller*>(user_data);
+ self->HideDash();
+ g_dbus_method_invocation_return_value(invocation, nullptr);
+ }
+}
+
+
}
}
diff --git a/dash/DashController.h b/dash/DashController.h
index a03745782..e3e210c1a 100644
--- a/dash/DashController.h
+++ b/dash/DashController.h
@@ -45,6 +45,7 @@ public:
typedef std::shared_ptr<Controller> Ptr;
Controller();
+ ~Controller();
nux::BaseWindow* window() const;
@@ -84,6 +85,12 @@ private:
void StartShowHideTimeline();
void OnViewShowHideFrame(double progress);
+ static void OnBusAcquired(GObject *obj, GAsyncResult *result, gpointer user_data);
+ static void OnDBusMethodCall(GDBusConnection* connection, const gchar* sender,
+ const gchar* object_path, const gchar* interface_name,
+ const gchar* method_name, GVariant* parameters,
+ GDBusMethodInvocation* invocation, gpointer user_data);
+
static void OnWindowConfigure(int width, int height, nux::Geometry& geo, void* data);
private:
@@ -100,6 +107,9 @@ private:
glib::SourceManager sources_;
Animator timeline_animator_;
UBusManager ubus_manager_;
+ unsigned int dbus_owner_;
+ glib::Object<GCancellable> dbus_connect_cancellable_;
+ static GDBusInterfaceVTable interface_vtable;
};
diff --git a/tests/autopilot/unity/emulators/dash.py b/tests/autopilot/unity/emulators/dash.py
index 22e5da883..0d38591e8 100644
--- a/tests/autopilot/unity/emulators/dash.py
+++ b/tests/autopilot/unity/emulators/dash.py
@@ -9,6 +9,7 @@
from __future__ import absolute_import
+from autopilot.emulators.dbus_handler import session_bus
from autopilot.emulators.X11 import Keyboard, Mouse
from autopilot.keybindings import KeybindingsHelper
from testtools.matchers import GreaterThan
@@ -16,7 +17,7 @@ from testtools.matchers import GreaterThan
from unity.emulators import UnityIntrospectionObject
import logging
from time import sleep
-
+import dbus
logger = logging.getLogger(__name__)
@@ -162,6 +163,13 @@ class DashController(UnityIntrospectionObject):
"""Get the dash view that's attached to this controller."""
return self.get_children_by_type(DashView)[0]
+ def hide_dash_via_dbus(self):
+ """ Emulate a DBus call for dash hiding """
+ dash_object = session_bus.get_object('com.canonical.Unity',
+ '/com/canonical/Unity/Dash')
+ dash_iface = dbus.Interface(dash_object, 'com.canonical.Unity.Dash')
+ dash_iface.HideDash()
+
class DashView(UnityIntrospectionObject):
"""The dash view."""
diff --git a/tests/autopilot/unity/tests/test_dash.py b/tests/autopilot/unity/tests/test_dash.py
index 305712c69..be2363e24 100644
--- a/tests/autopilot/unity/tests/test_dash.py
+++ b/tests/autopilot/unity/tests/test_dash.py
@@ -847,3 +847,12 @@ class PreviewNavigateTests(DashTestCase):
self.assertThat(self.dash.preview_displaying, Eventually(Equals(False)))
+class DashDBusIfaceTests(DashTestCase):
+ """Test the Unity dash DBus interface."""
+
+ def test_dash_hide(self):
+ """Ensure we can hide the dash via HideDash() dbus method."""
+ self.dash.ensure_visible()
+ self.dash.controller.hide_dash_via_dbus()
+ self.assertThat(self.dash.visible, Eventually(Equals(False)))
+ self.dash.ensure_hidden()