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

PhoshHome: Track folded/unfolded state



We fold/unfold the surface on home button clicks.

We use an enum since we might end up with half folded states
or a different state when using app switch via swipe.

This surface will later on have the app drawer.
Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>

Closes: #89
parent 271c86b0
......@@ -8,39 +8,92 @@
#include "config.h"
#include "home.h"
#include "shell.h"
#include "phosh-enums.h"
#include "osk/osk-button.h"
/**
* SECTION:phosh-home
* @short_description: The ome button at the bottom of the screen
* @short_description: The home screen (sometimes called overview) and the corrsponding
* button at the bottom of the screen
* @Title: PhoshHome
*
* 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 };
enum {
PROP_0,
PROP_HOME_STATE,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
struct _PhoshHome
{
PhoshLayerSurface parent;
GtkWidget *btn_home;
GtkWidget *btn_osk;
PhoshHomeState state;
};
G_DEFINE_TYPE(PhoshHome, phosh_home, PHOSH_TYPE_LAYER_SURFACE);
static void
phosh_home_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
PhoshHome *self = PHOSH_HOME (object);
switch (property_id) {
case PROP_HOME_STATE:
self->state = g_value_get_enum (value);
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HOME_STATE]);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
phosh_home_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
PhoshHome *self = PHOSH_HOME (object);
switch (property_id) {
case PROP_HOME_STATE:
g_value_set_enum (value, self->state);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
home_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[HOME_ACTIVATED], 0);
phosh_home_set_state (self, !self->state);
}
......@@ -82,13 +135,23 @@ phosh_home_class_init (PhoshHomeClass *klass)
object_class->constructed = phosh_home_constructed;
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);
object_class->set_property = phosh_home_set_property;
object_class->get_property = phosh_home_get_property;
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);
props[PROP_HOME_STATE] =
g_param_spec_enum ("state",
"Home State",
"The state of the home screen",
PHOSH_TYPE_HOME_STATE,
PHOSH_HOME_STATE_FOLDED,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
PHOSH_TYPE_OSK_BUTTON;
gtk_widget_class_set_template_from_resource (widget_class,
"/sm/puri/phosh/ui/home.ui");
......@@ -102,6 +165,8 @@ phosh_home_class_init (PhoshHomeClass *klass)
static void
phosh_home_init (PhoshHome *self)
{
self->state = PHOSH_HOME_STATE_FOLDED;
gtk_widget_init_template (GTK_WIDGET (self));
}
......@@ -123,3 +188,32 @@ phosh_home_new (struct zwlr_layer_shell_v1 *layer_shell,
"namespace", "phosh home",
NULL);
}
/**
* phosh_home_set_state:
*
* Set the state of the home screen. See #PhoshHomeState.
*/
void
phosh_home_set_state (PhoshHome *self, PhoshHomeState state)
{
g_return_if_fail (PHOSH_IS_HOME (self));
if (self->state == state)
return;
self->state = state;
g_debug ("Setting state to %s", g_enum_to_string (PHOSH_TYPE_HOME_STATE, state));
/* We don't change the exclusive zone since we don't want to push all clients upward */
if (state == PHOSH_HOME_STATE_UNFOLDED) {
int height;
phosh_shell_get_usable_area (phosh_shell_get_default (), NULL, NULL, NULL, &height);
phosh_layer_surface_set_size (PHOSH_LAYER_SURFACE (self), -1, PHOSH_HOME_BUTTON_HEIGHT + height);
} else {
phosh_layer_surface_set_size (PHOSH_LAYER_SURFACE (self), -1, PHOSH_HOME_BUTTON_HEIGHT);
}
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HOME_STATE]);
}
......@@ -12,7 +12,13 @@
#define PHOSH_HOME_BUTTON_HEIGHT 40
typedef enum {
PHOSH_HOME_STATE_FOLDED, /* Only home button is visiable */
PHOSH_HOME_STATE_UNFOLDED, /* Home screen takes the whole screen except the top panel */
} PhoshHomeState;
G_DECLARE_FINAL_TYPE (PhoshHome, phosh_home, PHOSH, HOME, PhoshLayerSurface)
GtkWidget * phosh_home_new (struct zwlr_layer_shell_v1 *layer_shell,
struct wl_output *wl_output);
void phosh_home_set_state (PhoshHome *self, PhoshHomeState state);
......@@ -12,6 +12,7 @@ phosh_resources = gnome.compile_resources(
)
phosh_enum_headers = [
'home.h',
]
phosh_enums = gnome.mkenums('phosh-enums',
......
/*** BEGIN file-header ***/
#include "config.h"
#include "home.h"
#include "phosh-enums.h"
/*** END file-header ***/
......
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