Commit a458518f authored by Guido Gunther's avatar Guido Gunther
Browse files

home: Add keyboard button



Add a keyboard button to the home buttons bar. This will allow to unfold
the OSK.
Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent 9468eaa2
Pipeline #1320 passed with stages
in 15 minutes and 14 seconds
......@@ -8,16 +8,19 @@
#include "config.h"
#include "home.h"
#include "osk/osk-button.h"
/**
* SECTION:phosh-home
* @short_description: The ome button at the bottom of the screen
* @Title: PhoshHome
*
* The #PhoshHome is displayed at the bottom of the screen.
* The #PhoshHome is displayed at the bottom of the screen. It features
* the home button and the button to toggle the OSK.
*/
enum {
HOME_ACTIVATED,
OSK_ACTIVATED,
N_SIGNALS
};
static guint signals[N_SIGNALS] = { 0 };
......@@ -25,6 +28,7 @@ static guint signals[N_SIGNALS] = { 0 };
typedef struct
{
GtkWidget *btn_home;
GtkWidget *btn_osk;
} PhoshHomePrivate;
......@@ -45,6 +49,15 @@ home_clicked_cb (PhoshHome *self, GtkButton *btn)
}
static void
osk_clicked_cb (PhoshHome *self, GtkButton *btn)
{
g_return_if_fail (PHOSH_IS_HOME (self));
g_return_if_fail (GTK_IS_BUTTON (btn));
g_signal_emit(self, signals[OSK_ACTIVATED], 0);
}
static void
phosh_home_constructed (GObject *object)
{
......@@ -57,6 +70,12 @@ phosh_home_constructed (GObject *object)
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->btn_osk,
"clicked",
G_CALLBACK (osk_clicked_cb),
self,
G_CONNECT_SWAPPED);
G_OBJECT_CLASS (phosh_home_parent_class)->constructed (object);
}
......@@ -72,10 +91,15 @@ phosh_home_class_init (PhoshHomeClass *klass)
signals[HOME_ACTIVATED] = g_signal_new ("home-activated",
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
NULL, G_TYPE_NONE, 0);
signals[OSK_ACTIVATED] = g_signal_new ("osk-activated",
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
NULL, G_TYPE_NONE, 0);
PHOSH_TYPE_OSK_BUTTON;
gtk_widget_class_set_template_from_resource (widget_class,
"/sm/puri/phosh/ui/home.ui");
gtk_widget_class_bind_template_child_private (widget_class, PhoshHome, btn_home);
gtk_widget_class_bind_template_child_private (widget_class, PhoshHome, btn_osk);
}
......
subdir('wwan')
subdir('monitor')
subdir('osk')
phosh_resources = gnome.compile_resources(
'phosh-resources',
......@@ -54,6 +55,7 @@ phosh_sources = [
phosh_resources,
phosh_wwan_sources,
phosh_monitor_sources,
phosh_osk_sources,
wl_proto_sources,
]
......
iface = 'phosh-osk0-dbus'
generated_osk_sources = gnome.gdbus_codegen(iface,
iface + '.xml',
namespace: 'PhoshOsk0',
object_manager: true)
phosh_osk_sources = [
'osk/osk-button.c',
generated_osk_sources,
]
/*
* Copyright (C) 2018 Purism SPC
* SPDX-License-Identifier: GPL-3.0+
* Author: Guido Günther <agx@sigxcpu.org>
*/
#define G_LOG_DOMAIN "phosh-osk-button"
#include "osk-button.h"
#include "phosh-osk0-dbus.h"
#include <gio/gio.h>
#include <gtk/gtk.h>
#define VIRTBOARD_DBUS_NAME "sm.puri.OSK0"
#define VIRTBOARD_DBUS_OBJECT "/sm/puri/OSK0"
/**
* SECTION:phosh-osk-button
* @short_description: A button that toggles the OSK
* @Title: PhoshOsk
*
* The #PhoshOskButton is responsible for toggling the on screen keyboard
*/
typedef struct
{
/* Currently the only impl. We can use an interface once we support
* different OSK types */
PhoshOsk0SmPuriOSK0 *proxy;
gboolean visible;
gboolean setting_visibility;
} PhoshOskButtonPrivate;
typedef struct _PhoshOskButton
{
GtkToggleButton parent;
} PhoshOskButton;
G_DEFINE_TYPE_WITH_PRIVATE (PhoshOskButton, phosh_osk_button, GTK_TYPE_TOGGLE_BUTTON)
static void
on_osk_show (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GVariant *variant;
GError *err = NULL;
variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &err);
if (!variant) {
g_warning ("Unable to toggle OSK: %s", err->message);
g_clear_error (&err);
return;
}
g_variant_unref (variant);
}
static void
phosh_osk_show (PhoshOskButton *self, gboolean show)
{
PhoshOskButtonPrivate *priv = phosh_osk_button_get_instance_private (self);
if (priv->proxy) {
phosh_osk0_sm_puri_osk0_call_set_visible (
priv->proxy,
show,
NULL,
(GAsyncReadyCallback) on_osk_show,
NULL);
}
}
static void
toggled_cb (PhoshOskButton *self, gpointer data)
{
PhoshOskButtonPrivate *priv = phosh_osk_button_get_instance_private (self);
priv->setting_visibility = TRUE;
priv->visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self));
phosh_osk_show (self, priv->visible);
priv->setting_visibility = FALSE;
}
static void
visibility_changed (PhoshOskButton *self, gboolean visible)
{
PhoshOskButtonPrivate *priv = phosh_osk_button_get_instance_private (self);
if (!priv->setting_visibility)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self), visible);
}
static void
dbus_props_changed_cb (PhoshOsk0SmPuriOSK0 *proxy,
GVariant *changed_properties,
GStrv invaliated,
gpointer *data)
{
PhoshOskButton *self = PHOSH_OSK_BUTTON (data);
char *property;
GVariantIter i;
GVariant *value;
g_variant_iter_init (&i, changed_properties);
while (g_variant_iter_next (&i, "{&sv}", &property, &value)) {
g_debug ("OSK property '%s' changed", property);
if (strcmp (property, "Visible") == 0) {
visibility_changed (self, g_variant_get_boolean (value));
}
g_variant_unref (value);
}
}
static void
dbus_name_owner_changed_cb (PhoshOskButton *self, gpointer data)
{
PhoshOskButtonPrivate *priv;
g_autofree char *name_owner = NULL;
g_return_if_fail (PHOSH_IS_OSK_BUTTON (self));
priv = phosh_osk_button_get_instance_private (self);
name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (priv->proxy));
g_debug ("OSK bus '%s' owned by %s", VIRTBOARD_DBUS_NAME, name_owner ? name_owner : "nobody");
if (name_owner) {
gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
} else {
gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
/* When there's no OSK we always want the button to be unpressed */
visibility_changed (self, FALSE);
};
}
static void
phosh_osk_button_constructed (GObject *object)
{
PhoshOskButton *self = PHOSH_OSK_BUTTON (object);
PhoshOskButtonPrivate *priv = phosh_osk_button_get_instance_private (self);
GError *err = NULL;
GtkWidget *image;
G_OBJECT_CLASS (phosh_osk_button_parent_class)->constructed (object);
priv->proxy = phosh_osk0_sm_puri_osk0_proxy_new_for_bus_sync(
G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
VIRTBOARD_DBUS_NAME,
VIRTBOARD_DBUS_OBJECT,
NULL,
&err);
if (priv->proxy == NULL) {
g_warning ("Failed to register with osk: %s", err->message);
g_clear_error (&err);
g_return_if_fail (priv->proxy);
}
g_signal_connect (
priv->proxy,
"g-properties-changed",
G_CALLBACK (dbus_props_changed_cb),
self);
g_signal_connect_swapped (
priv->proxy,
"notify::g-name-owner",
G_CALLBACK (dbus_name_owner_changed_cb),
self);
dbus_name_owner_changed_cb (self, NULL);
g_signal_connect (self,
"toggled",
G_CALLBACK (toggled_cb),
NULL);
image = gtk_image_new_from_icon_name ("input-keyboard-symbolic", GTK_ICON_SIZE_BUTTON);
gtk_button_set_image (GTK_BUTTON (self), image);
gtk_button_set_always_show_image (GTK_BUTTON (self), TRUE);
visibility_changed (self, phosh_osk0_sm_puri_osk0_get_visible (priv->proxy));
}
static void
phosh_osk_button_dispose (GObject *object)
{
PhoshOskButtonPrivate *priv = phosh_osk_button_get_instance_private (PHOSH_OSK_BUTTON(object));
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (phosh_osk_button_parent_class)->dispose (object);
}
static void
phosh_osk_button_class_init (PhoshOskButtonClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = phosh_osk_button_constructed;
object_class->dispose = phosh_osk_button_dispose;
}
static void
phosh_osk_button_init (PhoshOskButton *self)
{
}
GtkWidget *
phosh_osk_button_new (void)
{
return g_object_new (PHOSH_TYPE_OSK_BUTTON, NULL);
}
/*
* Copyright (C) 2018 Purism SPC
* SPDX-License-Identifier: GPL-3.0+
* Author: Guido Günther <agx@sigxcpu.org>
*/
#pragma once
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define PHOSH_TYPE_OSK_BUTTON (phosh_osk_button_get_type())
G_DECLARE_FINAL_TYPE (PhoshOskButton, phosh_osk_button, PHOSH, OSK_BUTTON, GtkToggleButton)
GtkWidget * phosh_osk_button_new (void);
G_END_DECLS
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<interface name="sm.puri.OSK0">
<method name="SetVisible">
<arg type="b" direction="in"/>
<doc:doc><doc:description>
Switch keyboard visibility
</doc:description></doc:doc>
</method>
<property name="Visible" type="b" access="read">
</property>
</interface>
</node>
......@@ -345,7 +345,6 @@ panels_create (PhoshShell *self)
"home-activated",
G_CALLBACK(home_activated_cb),
self);
}
......
......@@ -2,28 +2,34 @@
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-up-symbolic</property>
</object>
<template class="PhoshHome" parent="PhoshLayerSurface">
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkGrid">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_homogeneous">True</property>
<property name="column_homogeneous">True</property>
<child>
<object class="PhoshOskButton" id="btn_osk">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child type="center">
<object class="GtkButton" id="btn_home">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">image1</property>
<property name="hexpand">True</property>
<property name="image">img_home</property>
<property name="image_position">top</property>
<property name="always_show_image">True</property>
<style>
......@@ -31,11 +37,17 @@
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</template>
<object class="GtkImage" id="img_home">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-up-symbolic</property>
</object>
</interface>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment