Commit f7f17e7d authored by Guido Gunther's avatar Guido Gunther

WiP: menus: Switch to layer-shell protocol

Switch to wlroots layer-shell instead of weston's private desktop-shell
protocoll.
parent c591f6f6
......@@ -3,7 +3,7 @@
* SPDX-License-Identifier: GPL-3.0+
* Author: Guido Günther <agx@sigxcpu.org>
*
* Based on maynard whish is
* Based on maynard's favorites whish is
* Copyright (C) 2013 Collabora Ltd.
* Author: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
......@@ -30,10 +30,10 @@ typedef struct
struct _PhoshFavorites
{
PhoshMenuClass parent;
GtkWindowClass parent;
};
G_DEFINE_TYPE_WITH_PRIVATE(PhoshFavorites, phosh_favorites, PHOSH_TYPE_MENU)
G_DEFINE_TYPE_WITH_PRIVATE(PhoshFavorites, phosh_favorites, GTK_TYPE_WINDOW)
static void
......@@ -186,11 +186,7 @@ phosh_favorites_init (PhoshFavorites *self)
GtkWidget *
phosh_favorites_new (int position, const gpointer *shell)
phosh_favorites_new ()
{
return g_object_new (PHOSH_TYPE_FAVORITES,
"name", "favorites",
"shell", shell,
"position", position,
NULL);
return g_object_new (PHOSH_TYPE_FAVORITES, NULL);
}
......@@ -7,12 +7,12 @@
#ifndef PHOSH_FAVORITES_H
#define PHOSH_FAVORITES_H
#include "menu.h"
#include <gtk/gtk.h>
#define PHOSH_TYPE_FAVORITES (phosh_favorites_get_type())
G_DECLARE_FINAL_TYPE (PhoshFavorites, phosh_favorites, PHOSH, FAVORITES, PhoshMenu)
G_DECLARE_FINAL_TYPE (PhoshFavorites, phosh_favorites, PHOSH, FAVORITES, GtkWindow)
GtkWidget * phosh_favorites_new (int position, const gpointer *shell);
GtkWidget * phosh_favorites_new ();
#endif /* PHOSH_FAVORITES_H */
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3+
* Author: Guido Günther <agx@sigxcpu.org>
*/
#include <glib/gi18n.h>
#include "menu.h"
#include "phosh-mobile-shell-client-protocol.h"
/**
* SECTION:phosh-menu
* @short_description: A menu of the phosh wayland shell
* @Title: PhoshMenu
*
* The #PhoshMenu widget is a shell menu attached to a panel
* Don't let the wayland details leak to child classes.
*/
typedef struct
{
struct wl_surface *surface;
struct phosh_mobile_shell *mshell;
gboolean shown;
gchar *name;
int position;
} PhoshMenuPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (PhoshMenu, phosh_menu, GTK_TYPE_WINDOW)
enum {
PHOSH_MENU_PROP_0 = 0,
PHOSH_MENU_PROP_SHOWN,
PHOSH_MENU_PROP_NAME,
PHOSH_MENU_PROP_SHELL,
PHOSH_MENU_PROP_POSITION,
PHOSH_MENU_PROP_LAST_PROP,
};
static GParamSpec *props[PHOSH_MENU_PROP_LAST_PROP] = { NULL, };
enum {
TOGGLED = 1,
LAST_SIGNAL,
};
static guint signals [LAST_SIGNAL];
static void
phosh_menu_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
PhoshMenu *self = PHOSH_MENU (object);
PhoshMenuPrivate *priv = phosh_menu_get_instance_private(self);
switch (property_id) {
case PHOSH_MENU_PROP_SHOWN:
priv->shown = g_value_get_boolean (value);
break;
case PHOSH_MENU_PROP_NAME:
g_free (priv->name);
priv->name = g_value_dup_string (value);
break;
case PHOSH_MENU_PROP_SHELL:
priv->mshell = g_value_get_pointer (value);
break;
case PHOSH_MENU_PROP_POSITION:
priv->position = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
phosh_menu_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
PhoshMenu *self = PHOSH_MENU (object);
PhoshMenuPrivate *priv = phosh_menu_get_instance_private(self);
switch (property_id) {
case PHOSH_MENU_PROP_SHOWN:
g_value_set_boolean (value, priv->shown);
break;
case PHOSH_MENU_PROP_NAME:
g_value_set_string (value, priv->name);
break;
case PHOSH_MENU_PROP_SHELL:
g_value_set_pointer (value, priv->mshell);
case PHOSH_MENU_PROP_POSITION:
g_value_set_int (value, priv->position);
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
phosh_menu_constructed (GObject *object)
{
PhoshMenu *self = PHOSH_MENU (object);
PhoshMenuPrivate *priv = phosh_menu_get_instance_private (self);
GdkWindow *gdk_window;
g_autofree gchar *name;;
G_OBJECT_CLASS (phosh_menu_parent_class)->constructed (object);
name = g_strdup_printf("phosh-menu-%s", priv->name);
/* window properties */
gtk_window_set_title (GTK_WINDOW (self), name);
gtk_window_set_decorated (GTK_WINDOW (self), FALSE);
gtk_widget_realize(GTK_WIDGET (self));
gtk_style_context_add_class (
gtk_widget_get_style_context (GTK_WIDGET (self)),
"phosh-menu");
gtk_style_context_add_class (
gtk_widget_get_style_context (GTK_WIDGET (self)),
name);
gdk_window = gtk_widget_get_window (GTK_WIDGET (self));
gdk_wayland_window_set_use_custom_surface (gdk_window);
priv->surface = gdk_wayland_window_get_wl_surface (gdk_window);
g_return_if_fail (priv->surface != NULL);
phosh_mobile_shell_set_panel_menu (priv->mshell, priv->surface);
phosh_mobile_shell_set_menu_position(priv->mshell,
priv->surface,
priv->position);
}
static void
phosh_menu_finalize (GObject *object)
{
PhoshMenuPrivate *priv = phosh_menu_get_instance_private (PHOSH_MENU(object));
GObjectClass *parent_class = G_OBJECT_CLASS (phosh_menu_parent_class);
g_free (priv->name);
if (parent_class->finalize != NULL)
parent_class->finalize (object);
}
static void
phosh_menu_class_init (PhoshMenuClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = phosh_menu_constructed;
object_class->finalize = phosh_menu_finalize;
object_class->set_property = phosh_menu_set_property;
object_class->get_property = phosh_menu_get_property;
/**
* PhoshMenu::toggled:
* @self: The #PhoshMenu instance.
*
* This signal is emitted when the menu state changes.
* That is if it's shown or hidden on the screen.
*/
signals [TOGGLED] = g_signal_new ("toggled",
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
NULL, G_TYPE_NONE, 0);
props[PHOSH_MENU_PROP_SHOWN] = g_param_spec_boolean ("shown",
"menu shown",
"Whether the menu is shown on screen",
FALSE,
G_PARAM_READABLE);
props[PHOSH_MENU_PROP_NAME] = g_param_spec_string ("name",
"menu name",
"the menus name",
"unnamed",
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
props[PHOSH_MENU_PROP_SHELL] = g_param_spec_pointer ("shell",
"mobile shell",
"the mobile shell",
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
props[PHOSH_MENU_PROP_POSITION] = g_param_spec_int ("position",
"menu position",
"menu position on top bar",
0,
INT_MAX,
PHOSH_MOBILE_SHELL_MENU_POSITION_LEFT,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
g_object_class_install_properties (object_class, PHOSH_MENU_PROP_LAST_PROP, props);
}
/**
* phosh_menu_new:
*
* Create a new #PhoshMenu widget.
*
* Returns: the newly created #PhoshMenu widget
*
*/
GtkWidget *
phosh_menu_new (const char* name, int position,
const gpointer *shell)
{
return g_object_new (PHOSH_TYPE_MENU,
"name", name,
"shell", shell,
"position", position,
NULL);
}
static void
phosh_menu_init (PhoshMenu *self)
{
PhoshMenuPrivate *priv = phosh_menu_get_instance_private(self);
priv->shown = FALSE;
priv->name = NULL;
priv->mshell = NULL;
}
gboolean
phosh_menu_is_shown (PhoshMenu *self)
{
PhoshMenuPrivate *priv = phosh_menu_get_instance_private(self);
return priv->shown;
}
void
phosh_menu_hide (PhoshMenu *self)
{
PhoshMenuPrivate *priv = phosh_menu_get_instance_private(self);
g_return_if_fail (priv->mshell);
g_return_if_fail (priv->surface);
if (priv->shown)
phosh_mobile_shell_hide_panel_menu(priv->mshell,
priv->surface);
priv->shown = FALSE;
}
void
phosh_menu_show (PhoshMenu *self)
{
PhoshMenuPrivate *priv = phosh_menu_get_instance_private(self);
g_return_if_fail (priv->mshell);
g_return_if_fail (priv->surface);
if (!priv->shown)
phosh_mobile_shell_show_panel_menu(priv->mshell,
priv->surface);
priv->shown = TRUE;
}
gboolean
phosh_menu_toggle (PhoshMenu *self)
{
PhoshMenuPrivate *priv = phosh_menu_get_instance_private(self);
priv->shown ? phosh_menu_hide (self) : phosh_menu_show (self);
return priv->shown;
}
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3+
* Author: Guido Günther <agx@sigxcpu.org>
*/
#ifndef PHOSH_MENU_H
#define PHOSH_MENU_H
#include <gtk/gtk.h>
#include <gdk/gdkwayland.h>
G_BEGIN_DECLS
#define PHOSH_TYPE_MENU (phosh_menu_get_type())
G_DECLARE_DERIVABLE_TYPE (PhoshMenu, phosh_menu, PHOSH, MENU, GtkWindow)
/**
* PhoshMenuClass
* @parent_class: The parent class
*/
struct _PhoshMenuClass
{
GtkWindowClass parent_class;
};
GtkWidget * phosh_menu_new (const char* name,
int position,
const gpointer *shell);
gboolean phosh_menu_is_shown (PhoshMenu *self);
void phosh_menu_show (PhoshMenu *self);
void phosh_menu_hide (PhoshMenu *self);
gboolean phosh_menu_toggle (PhoshMenu *self);
G_END_DECLS
#endif /* PHOSH_MENU_H */
......@@ -35,8 +35,6 @@ phosh_sources = [
'favorites.h',
'lockscreen.c',
'lockscreen.h',
'menu.c',
'menu.h',
'panel.c',
'panel.h',
'phosh.c',
......
......@@ -66,10 +66,10 @@ typedef struct
gulong unlock_handler_id;
/* Favorites menu */
GtkWidget *favorites;
struct elem *favorites;
/* Settings menu */
GtkWidget *settings;
struct elem *settings;
} PhoshShellPrivate;
......@@ -125,46 +125,103 @@ lockscreen_unlock_cb (PhoshShell *self, PhoshLockscreen *window)
static void
favorites_activated_cb (PhoshShell *self,
PhoshPanel *window)
app_launched_cb (PhoshShell *self,
PhoshFavorites *favorites)
{
PhoshShellPrivate *priv = phosh_shell_get_instance_private (self);
g_return_if_fail (priv->favorites);
phosh_menu_toggle (PHOSH_MENU (priv->favorites));
gtk_window_close (GTK_WINDOW (priv->favorites->window));
gtk_widget_destroy (GTK_WIDGET (priv->favorites->window));
free (priv->favorites);
priv->favorites = NULL;
}
static void
app_launched_cb (PhoshShell *self,
PhoshFavorites *favorites)
favorites_activated_cb (PhoshShell *self,
PhoshPanel *window)
{
PhoshShellPrivate *priv = phosh_shell_get_instance_private (self);
GdkWindow *gdk_window;
struct elem *favorites;
g_return_if_fail (priv->favorites);
phosh_menu_hide (PHOSH_MENU (priv->favorites));
if (priv->favorites)
return;
favorites = calloc (1, sizeof *favorites);
favorites->window = phosh_favorites_new ();
gdk_window = gtk_widget_get_window (favorites->window);
gdk_wayland_window_set_use_custom_surface (gdk_window);
favorites->wl_surface = gdk_wayland_window_get_wl_surface (gdk_window);
favorites->layer_surface = zwlr_layer_shell_v1_get_layer_surface(priv->layer_shell,
favorites->wl_surface,
priv->output,
ZWLR_LAYER_SHELL_V1_LAYER_TOP,
"favorites");
zwlr_layer_surface_v1_set_anchor(favorites->layer_surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
zwlr_layer_surface_v1_set_exclusive_zone(favorites->layer_surface, FALSE);
zwlr_layer_surface_v1_set_size(favorites->layer_surface, 100, 100);
zwlr_layer_surface_v1_add_listener(favorites->layer_surface, &layer_surface_listener, favorites);
wl_surface_commit(favorites->wl_surface);
priv->favorites = favorites;
g_signal_connect_swapped (priv->favorites->window,
"app-launched",
G_CALLBACK(app_launched_cb),
self);
}
static void
settings_activated_cb (PhoshShell *self,
PhoshPanel *window)
setting_done_cb (PhoshShell *self,
PhoshSettings *settings)
{
PhoshShellPrivate *priv = phosh_shell_get_instance_private (self);
g_return_if_fail (priv->settings);
phosh_menu_toggle (PHOSH_MENU (priv->settings));
gtk_window_close (GTK_WINDOW (priv->settings->window));
gtk_widget_destroy (GTK_WIDGET (priv->settings->window));
free (priv->settings);
priv->settings = NULL;
}
static void
setting_done_cb (PhoshShell *self,
PhoshFavorites *favorites)
settings_activated_cb (PhoshShell *self,
PhoshPanel *window)
{
PhoshShellPrivate *priv = phosh_shell_get_instance_private (self);
GdkWindow *gdk_window;
struct elem *settings;
g_return_if_fail (priv->settings);
phosh_menu_hide (PHOSH_MENU (priv->settings));
if (priv->settings)
return;
settings = calloc (1, sizeof *settings);
settings->window = phosh_settings_new ();
gdk_window = gtk_widget_get_window (settings->window);
gdk_wayland_window_set_use_custom_surface (gdk_window);
settings->wl_surface = gdk_wayland_window_get_wl_surface (gdk_window);
settings->layer_surface = zwlr_layer_shell_v1_get_layer_surface(priv->layer_shell,
settings->wl_surface,
priv->output,
ZWLR_LAYER_SHELL_V1_LAYER_TOP,
"settings");
zwlr_layer_surface_v1_set_anchor(settings->layer_surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
zwlr_layer_surface_v1_set_exclusive_zone(settings->layer_surface, FALSE);
zwlr_layer_surface_v1_set_size(settings->layer_surface, 280, 100);
zwlr_layer_surface_v1_add_listener(settings->layer_surface, &layer_surface_listener, settings);
wl_surface_commit(settings->wl_surface);
priv->settings = settings;
g_signal_connect_swapped (priv->settings->window,
"setting-done",
G_CALLBACK(setting_done_cb),
self);
}
......@@ -198,43 +255,6 @@ lockscreen_create (PhoshShell *self)
}
static void
favorites_create (PhoshShell *self)
{
PhoshShellPrivate *priv = phosh_shell_get_instance_private (self);
#if 0
priv->favorites = phosh_favorites_new (PHOSH_MOBILE_SHELL_MENU_POSITION_LEFT,
(gpointer) priv->mshell);
#endif
gtk_widget_show_all (priv->favorites);
g_signal_connect_swapped (priv->favorites,
"app-launched",
G_CALLBACK(app_launched_cb),
self);
}
static void
settings_create (PhoshShell *self)
{
PhoshShellPrivate *priv = phosh_shell_get_instance_private (self);
#if 0
priv->settings = phosh_settings_new (PHOSH_MOBILE_SHELL_MENU_POSITION_RIGHT,
(gpointer) priv->mshell);
#endif
gtk_widget_show_all (priv->settings);
g_signal_connect_swapped (priv->settings,
"setting-done",
G_CALLBACK(setting_done_cb),
self);
}
static void
panel_create (PhoshShell *self)
{
......@@ -339,36 +359,6 @@ env_setup ()
}
static void
shell_configure (PhoshShell *self,
uint32_t edges,
struct wl_surface *surface,
int32_t width, int32_t height)
{
PhoshShellPrivate *priv = phosh_shell_get_instance_private (self);
gtk_widget_set_size_request (priv->background->window,
width, height);
/* Create menus once we now the panel's position */
if (!priv->favorites)
favorites_create (self);
if (!priv->settings)
settings_create (self);
}
static void
phosh_mobile_shell_configure (void *data,
struct phosh_mobile_shell *phosh_mobile_shell,
uint32_t edges,
struct wl_surface *surface,
int32_t width, int32_t height)
{
shell_configure(data, edges, surface, width, height);
}
static void
phosh_mobile_shell_prepare_lock_surface (void *data,
struct phosh_mobile_shell *phosh_mobile_shell)
......@@ -381,15 +371,6 @@ phosh_mobile_shell_prepare_lock_surface (void *data,
}
#if 0
static const struct phosh_mobile_shell_listener mshell_listener = {
phosh_mobile_shell_configure,
phosh_mobile_shell_prepare_lock_surface,
phosh_mobile_shell_grab_cursor
};
#endif
static void
registry_handle_global (void *data,
struct wl_registry *registry,
......
......@@ -38,11 +38,11 @@ typedef struct
typedef struct _PhoshSettings
{
PhoshMenu parent;
GtkWindow parent;
} PhoshSettings;
G_DEFINE_TYPE_WITH_PRIVATE (PhoshSettings, phosh_settings, PHOSH_TYPE_MENU)
G_DEFINE_TYPE_WITH_PRIVATE (PhoshSettings, phosh_settings, GTK_TYPE_WINDOW)
GtkWidget *phosh_settings (const char* name)
......@@ -97,6 +97,12 @@ phosh_settings_constructed (GObject *object)
PhoshSettingsPrivate *priv = phosh_settings_get_instance_private (self);
GtkWidget *image;
/* window properties */
gtk_window_set_title (GTK_WINDOW (self), "phosh settings");
gtk_window_set_decorated (GTK_WINDOW (self), FALSE);
gtk_window_resize (GTK_WINDOW (self), 100, 100);
gtk_widget_realize(GTK_WIDGET (self));
priv->adj_brightness = gtk_adjustment_new (0, 0, 100, 1, 10, 10);
gtk_range_set_adjustment (GTK_RANGE (priv->scale_brightness), priv->adj_brightness);
gtk_range_set_round_digits (GTK_RANGE (priv->scale_brightness), 0);
......@@ -167,11 +173,7 @@ phosh_settings_init (PhoshSettings *self)
}
GtkWidget *
phosh_settings_new (int position, const gpointer *shell)
phosh_settings_new ()
{
return g_object_new (PHOSH_TYPE_SETTINGS,
"name", "settings",
"shell", shell,
"position", position,
NULL);
return g_object_new (PHOSH_TYPE_SETTINGS, NULL);
}
......@@ -12,8 +12,8 @@
#define PHOSH_TYPE_SETTINGS (phosh_settings_get_type())
G_DECLARE_FINAL_TYPE (PhoshSettings, phosh_settings, PHOSH, SETTINGS, PhoshMenu)
G_DECLARE_FINAL_TYPE (PhoshSettings, phosh_settings, PHOSH, SETTINGS, GtkWindow)
GtkWidget * phosh_settings_new (int position, const gpointer* shell);
GtkWidget * phosh_settings_new ();
#endif /* PHOSH_SETTINGS_H */
......@@ -2,7 +2,7 @@
<!-- Generated with glade 3.20.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<template class="PhoshSettings" parent="PhoshMenu">
<template class="PhoshSettings" parent="GtkWindow">
<property name="width_request">250</property>
<property name="can_focus">False</property>
<child>
......
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