diff --git a/src/favorites.c b/src/favorites.c index 225a32e5a531df179881b403a025b93de3030281..df7e6703d523b3e0b52db0324b796c1e8f9dcf2c 100644 --- a/src/favorites.c +++ b/src/favorites.c @@ -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); } diff --git a/src/favorites.h b/src/favorites.h index fbec412b9b2959f7bf3a2a678de96b13d2b5fa03..042d0be1adcf8bf5d70f0764d7b5a47a392cf789 100644 --- a/src/favorites.h +++ b/src/favorites.h @@ -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 */ diff --git a/src/menu.c b/src/menu.c deleted file mode 100644 index cdb9b089fd5fd242c416018adf17ca02d1a8b56a..0000000000000000000000000000000000000000 --- a/src/menu.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - * 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; -} diff --git a/src/menu.h b/src/menu.h deleted file mode 100644 index bc6935ea4a77be802fd90cbcc37b3fa44afe61d8..0000000000000000000000000000000000000000 --- a/src/menu.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 */ diff --git a/src/meson.build b/src/meson.build index bd80125276ef8b6c3362ccba3b2c404bc49d3d25..f39de3e334425c85ed2ff6c559f4be6360e58570 100644 --- a/src/meson.build +++ b/src/meson.build @@ -35,8 +35,6 @@ phosh_sources = [ 'favorites.h', 'lockscreen.c', 'lockscreen.h', - 'menu.c', - 'menu.h', 'panel.c', 'panel.h', 'phosh.c', diff --git a/src/phosh.c b/src/phosh.c index e7e7804486b4f2c496dd202e3998a6ee1cf0003a..0bbadc7eddf3bd4d3d606e9c23e989363259abca 100644 --- a/src/phosh.c +++ b/src/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, diff --git a/src/settings.c b/src/settings.c index 8a76c130d009046a61abd23e582621868176b11a..df06a6ef2791abe488305049a8963f68aaf187d7 100644 --- a/src/settings.c +++ b/src/settings.c @@ -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); } diff --git a/src/settings.h b/src/settings.h index 87af148b6ea0347a263a6ecc26a454d83a393ed5..978ca6c1471638bc107c4c26fc071d86dc924000 100644 --- a/src/settings.h +++ b/src/settings.h @@ -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 */ diff --git a/src/ui/settings-menu.ui b/src/ui/settings-menu.ui index 3b928cccb85eddd8548c5842c31dd8c6518136fa..c30427b5a6d7938f01bca06c886345216c1441fd 100644 --- a/src/ui/settings-menu.ui +++ b/src/ui/settings-menu.ui @@ -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>