Verified Commit 76bf5422 authored by Sebastian Krzyszkowiak's avatar Sebastian Krzyszkowiak
Browse files

PhoshApp: Rename to PhoshActivity

Single application can be represented by multiple PhoshApps. It's also
not a window, as in the future, multiple windows may be represented
as a single PhoshApp as well - therefore, PhoshActivity seems to be
the most fitting name to this entity.
parent 532cfaf0
Pipeline #25771 passed with stages
in 5 minutes and 29 seconds
data/sm.puri.Phosh.desktop.in.in
data/phosh.session.desktop.in.in
src/app.c
src/activity.c
src/auth.c
src/background.c
src/batteryinfo.c
......
......@@ -4,28 +4,28 @@
* Author: Guido Günther <agx@sigxcpu.org>
*/
#define G_LOG_DOMAIN "phosh-app"
#define G_LOG_DOMAIN "phosh-activity"
#include "config.h"
#include "app.h"
#include "activity.h"
#include "shell.h"
#include <gio/gdesktopappinfo.h>
/**
* SECTION:phosh-app
* SECTION:phosh-activity
* @short_description: An app in the faovorites overview
* @Title: PhoshApp
* @Title: PhoshActivity
*
* The #PhoshApp is used to select a running application
* The #PhoshActivity is used to select a running application
* in the favorites overview.
*/
// Icons actually sized according to the pixel-size set in the template
#define APP_ICON_SIZE -1
#define ACTIVITY_ICON_SIZE -1
enum {
APP_CLOSED,
ACTIVITY_CLOSED,
N_SIGNALS
};
static guint signals[N_SIGNALS] = { 0 };
......@@ -57,25 +57,25 @@ typedef struct
char *app_id;
char *title;
GDesktopAppInfo *info;
} PhoshAppPrivate;
} PhoshActivityPrivate;
struct _PhoshApp
struct _PhoshActivity
{
GtkButton parent;
};
G_DEFINE_TYPE_WITH_PRIVATE(PhoshApp, phosh_app, GTK_TYPE_BUTTON)
G_DEFINE_TYPE_WITH_PRIVATE(PhoshActivity, phosh_activity, GTK_TYPE_BUTTON)
static void
phosh_app_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
phosh_activity_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
PhoshApp *self = PHOSH_APP (object);
PhoshAppPrivate *priv = phosh_app_get_instance_private(self);
PhoshActivity *self = PHOSH_ACTIVITY (object);
PhoshActivityPrivate *priv = phosh_activity_get_instance_private(self);
switch (property_id) {
case PROP_APP_ID:
......@@ -116,13 +116,13 @@ phosh_app_set_property (GObject *object,
static void
phosh_app_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
phosh_activity_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
PhoshApp *self = PHOSH_APP (object);
PhoshAppPrivate *priv = phosh_app_get_instance_private(self);
PhoshActivity *self = PHOSH_ACTIVITY (object);
PhoshActivityPrivate *priv = phosh_activity_get_instance_private(self);
switch (property_id) {
case PROP_APP_ID:
......@@ -151,20 +151,20 @@ phosh_app_get_property (GObject *object,
static void
on_btn_close_clicked (PhoshApp *self, GtkButton *button)
on_btn_close_clicked (PhoshActivity *self, GtkButton *button)
{
g_return_if_fail (PHOSH_IS_APP (self));
g_return_if_fail (PHOSH_IS_ACTIVITY (self));
g_return_if_fail (GTK_IS_BUTTON (button));
g_signal_emit(self, signals[APP_CLOSED], 0);
g_signal_emit(self, signals[ACTIVITY_CLOSED], 0);
}
static void
phosh_app_constructed (GObject *object)
phosh_activity_constructed (GObject *object)
{
PhoshApp *self = PHOSH_APP (object);
PhoshAppPrivate *priv = phosh_app_get_instance_private (self);
PhoshActivity *self = PHOSH_ACTIVITY (object);
PhoshActivityPrivate *priv = phosh_activity_get_instance_private (self);
g_autofree gchar *desktop_id = NULL;
g_autofree gchar *name = NULL;
......@@ -190,11 +190,11 @@ phosh_app_constructed (GObject *object)
if (priv->info) {
gtk_image_set_from_gicon (GTK_IMAGE (priv->icon),
g_app_info_get_icon (G_APP_INFO (priv->info)),
APP_ICON_SIZE);
ACTIVITY_ICON_SIZE);
} else {
gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
"missing-image",
APP_ICON_SIZE);
ACTIVITY_ICON_SIZE);
}
g_signal_connect_swapped (priv->btn_close,
......@@ -202,55 +202,55 @@ phosh_app_constructed (GObject *object)
(GCallback) on_btn_close_clicked,
self);
G_OBJECT_CLASS (phosh_app_parent_class)->constructed (object);
G_OBJECT_CLASS (phosh_activity_parent_class)->constructed (object);
}
static void
phosh_app_dispose (GObject *object)
phosh_activity_dispose (GObject *object)
{
PhoshApp *self = PHOSH_APP (object);
PhoshAppPrivate *priv = phosh_app_get_instance_private (self);
PhoshActivity *self = PHOSH_ACTIVITY (object);
PhoshActivityPrivate *priv = phosh_activity_get_instance_private (self);
g_clear_object (&priv->info);
G_OBJECT_CLASS (phosh_app_parent_class)->dispose (object);
G_OBJECT_CLASS (phosh_activity_parent_class)->dispose (object);
}
static void
phosh_app_finalize (GObject *object)
phosh_activity_finalize (GObject *object)
{
PhoshApp *self = PHOSH_APP (object);
PhoshAppPrivate *priv = phosh_app_get_instance_private (self);
PhoshActivity *self = PHOSH_ACTIVITY (object);
PhoshActivityPrivate *priv = phosh_activity_get_instance_private (self);
g_free (priv->app_id);
g_free (priv->title);
G_OBJECT_CLASS (phosh_app_parent_class)->finalize (object);
G_OBJECT_CLASS (phosh_activity_parent_class)->finalize (object);
}
static GtkSizeRequestMode
phosh_app_get_request_mode (GtkWidget *widgte)
phosh_activity_get_request_mode (GtkWidget *widgte)
{
return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
}
static void
phosh_app_get_preferred_height_for_width (GtkWidget *widget,
int width,
int *min,
int *nat)
phosh_activity_get_preferred_height_for_width (GtkWidget *widget,
int width,
int *min,
int *nat)
{
PhoshAppPrivate *priv;
PhoshActivityPrivate *priv;
int smallest = 0;
int size = 420;
int box_smallest = 0;
g_return_if_fail (PHOSH_IS_APP (widget));
priv = phosh_app_get_instance_private (PHOSH_APP (widget));
g_return_if_fail (PHOSH_IS_ACTIVITY (widget));
priv = phosh_activity_get_instance_private (PHOSH_ACTIVITY (widget));
GTK_WIDGET_CLASS (phosh_app_parent_class)->get_preferred_height_for_width (widget,
GTK_WIDGET_CLASS (phosh_activity_parent_class)->get_preferred_height_for_width (widget,
width,
&smallest,
NULL);
......@@ -272,17 +272,17 @@ phosh_app_get_preferred_height_for_width (GtkWidget *widget,
}
static void
phosh_app_get_preferred_width (GtkWidget *widget, int *min, int *nat)
phosh_activity_get_preferred_width (GtkWidget *widget, int *min, int *nat)
{
PhoshAppPrivate *priv;
PhoshActivityPrivate *priv;
int smallest = 0;
int box_smallest = 0;
int size = 250;
g_return_if_fail (PHOSH_IS_APP (widget));
priv = phosh_app_get_instance_private (PHOSH_APP (widget));
g_return_if_fail (PHOSH_IS_ACTIVITY (widget));
priv = phosh_activity_get_instance_private (PHOSH_ACTIVITY (widget));
GTK_WIDGET_CLASS (phosh_app_parent_class)->get_preferred_width (widget,
GTK_WIDGET_CLASS (phosh_activity_parent_class)->get_preferred_width (widget,
&smallest,
NULL);
gtk_widget_get_preferred_width (priv->box, &box_smallest, NULL);
......@@ -303,31 +303,31 @@ phosh_app_get_preferred_width (GtkWidget *widget, int *min, int *nat)
}
static void
phosh_app_get_preferred_width_for_height (GtkWidget *widget,
int height,
int *min,
int *nat)
phosh_activity_get_preferred_width_for_height (GtkWidget *widget,
int height,
int *min,
int *nat)
{
phosh_app_get_preferred_width (widget, min, nat);
phosh_activity_get_preferred_width (widget, min, nat);
}
static void
phosh_app_class_init (PhoshAppClass *klass)
phosh_activity_class_init (PhoshActivityClass *klass)
{
GObjectClass *object_class = (GObjectClass *)klass;
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructed = phosh_app_constructed;
object_class->dispose = phosh_app_dispose;
object_class->finalize = phosh_app_finalize;
object_class->constructed = phosh_activity_constructed;
object_class->dispose = phosh_activity_dispose;
object_class->finalize = phosh_activity_finalize;
object_class->set_property = phosh_app_set_property;
object_class->get_property = phosh_app_get_property;
object_class->set_property = phosh_activity_set_property;
object_class->get_property = phosh_activity_get_property;
widget_class->get_request_mode = phosh_app_get_request_mode;
widget_class->get_preferred_width = phosh_app_get_preferred_width;
widget_class->get_preferred_height_for_width = phosh_app_get_preferred_height_for_width;
widget_class->get_preferred_width_for_height = phosh_app_get_preferred_width_for_height;
widget_class->get_request_mode = phosh_activity_get_request_mode;
widget_class->get_preferred_width = phosh_activity_get_preferred_width;
widget_class->get_preferred_height_for_width = phosh_activity_get_preferred_height_for_width;
widget_class->get_preferred_width_for_height = phosh_activity_get_preferred_width_for_height;
props[PROP_APP_ID] =
g_param_spec_string (
......@@ -387,25 +387,25 @@ phosh_app_class_init (PhoshAppClass *klass)
g_object_class_install_properties (object_class, LAST_PROP, props);
signals[APP_CLOSED] = g_signal_new ("app-closed",
signals[ACTIVITY_CLOSED] = g_signal_new ("activity-closed",
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
NULL, G_TYPE_NONE, 0);
gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/phosh/ui/app.ui");
gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/phosh/ui/activity.ui");
gtk_widget_class_bind_template_child_private (widget_class, PhoshApp, app_name);
gtk_widget_class_bind_template_child_private (widget_class, PhoshApp, icon);
gtk_widget_class_bind_template_child_private (widget_class, PhoshApp, box);
gtk_widget_class_bind_template_child_private (widget_class, PhoshApp, btn_close);
gtk_widget_class_bind_template_child_private (widget_class, PhoshActivity, app_name);
gtk_widget_class_bind_template_child_private (widget_class, PhoshActivity, icon);
gtk_widget_class_bind_template_child_private (widget_class, PhoshActivity, box);
gtk_widget_class_bind_template_child_private (widget_class, PhoshActivity, btn_close);
gtk_widget_class_set_css_name (widget_class, "phosh-app");
gtk_widget_class_set_css_name (widget_class, "phosh-activity");
}
static void
phosh_app_init (PhoshApp *self)
phosh_activity_init (PhoshActivity *self)
{
PhoshAppPrivate *priv = phosh_app_get_instance_private (self);
PhoshActivityPrivate *priv = phosh_activity_get_instance_private (self);
gtk_widget_init_template (GTK_WIDGET (self));
......@@ -417,10 +417,10 @@ phosh_app_init (PhoshApp *self)
GtkWidget *
phosh_app_new (const char *app_id,
const char *title)
phosh_activity_new (const char *app_id,
const char *title)
{
return g_object_new (PHOSH_TYPE_APP,
return g_object_new (PHOSH_TYPE_ACTIVITY,
"app-id", app_id,
"title", title,
NULL);
......@@ -428,24 +428,24 @@ phosh_app_new (const char *app_id,
const char *
phosh_app_get_app_id (PhoshApp *self)
phosh_activity_get_app_id (PhoshActivity *self)
{
PhoshAppPrivate *priv;
PhoshActivityPrivate *priv;
g_return_val_if_fail (PHOSH_IS_APP (self), NULL);
priv = phosh_app_get_instance_private (self);
g_return_val_if_fail (PHOSH_IS_ACTIVITY (self), NULL);
priv = phosh_activity_get_instance_private (self);
return priv->app_id;
}
const char *
phosh_app_get_title (PhoshApp *self)
phosh_activity_get_title (PhoshActivity *self)
{
PhoshAppPrivate *priv;
PhoshActivityPrivate *priv;
g_return_val_if_fail (PHOSH_IS_APP (self), NULL);
priv = phosh_app_get_instance_private (self);
g_return_val_if_fail (PHOSH_IS_ACTIVITY (self), NULL);
priv = phosh_activity_get_instance_private (self);
return priv->title;
}
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#pragma once
#include <gtk/gtk.h>
#define PHOSH_TYPE_ACTIVITY (phosh_activity_get_type())
G_DECLARE_FINAL_TYPE (PhoshActivity, phosh_activity, PHOSH, ACTIVITY, GtkButton)
GtkWidget *phosh_activity_new (const char *app_id,
const char *title);
const char *phosh_activity_get_app_id (PhoshActivity *self);
const char *phosh_activity_get_title (PhoshActivity *self);
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#pragma once
#include <gtk/gtk.h>
#define PHOSH_TYPE_APP (phosh_app_get_type())
G_DECLARE_FINAL_TYPE (PhoshApp, phosh_app, PHOSH, APP, GtkButton)
GtkWidget *phosh_app_new (const char *app_id,
const char *title);
const char *phosh_app_get_app_id (PhoshApp *self);
const char *phosh_app_get_title (PhoshApp *self);
......@@ -13,7 +13,7 @@
#include "config.h"
#include "favorites.h"
#include "app.h"
#include "activity.h"
#include "shell.h"
#include "util.h"
#include "toplevel-manager.h"
......@@ -25,9 +25,9 @@
#define FAVORITES_ICON_SIZE 64
enum {
APP_LAUNCHED,
APP_RAISED,
APP_CLOSED,
ACTIVITY_LAUNCHED,
ACTIVITY_RAISED,
ACTIVITY_CLOSED,
SELECTION_ABORTED,
N_SIGNALS
};
......@@ -40,9 +40,9 @@ typedef struct
GtkWidget *fb_favorites;
GSettings *settings;
/* Running apps */
GtkWidget *evbox_running_apps;
GtkWidget *box_running_apps;
/* Running activities */
GtkWidget *evbox_running_activities;
GtkWidget *box_running_activities;
} PhoshFavoritesPrivate;
......@@ -56,55 +56,55 @@ G_DEFINE_TYPE_WITH_PRIVATE(PhoshFavorites, phosh_favorites, GTK_TYPE_WINDOW)
static void
on_app_clicked (PhoshFavorites *self, PhoshApp *app)
on_activity_clicked (PhoshFavorites *self, PhoshActivity *activity)
{
PhoshToplevel *toplevel;
g_return_if_fail (PHOSH_IS_FAVORITES (self));
g_return_if_fail (PHOSH_IS_APP (app));
g_return_if_fail (PHOSH_IS_ACTIVITY (activity));
toplevel = g_object_get_data(G_OBJECT (app), "toplevel");
toplevel = g_object_get_data(G_OBJECT (activity), "toplevel");
g_return_if_fail (PHOSH_IS_TOPLEVEL (toplevel));
g_debug("Will raise %s (%s)",
phosh_app_get_app_id (app),
phosh_app_get_title (app));
phosh_activity_get_app_id (activity),
phosh_activity_get_title (activity));
phosh_toplevel_raise (toplevel, phosh_wayland_get_wl_seat (phosh_wayland_get_default ()));
g_signal_emit(self, signals[APP_RAISED], 0);
g_signal_emit(self, signals[ACTIVITY_RAISED], 0);
}
static void
on_app_closed (PhoshFavorites *self, PhoshApp *app)
on_activity_closed (PhoshFavorites *self, PhoshActivity *activity)
{
PhoshToplevel *toplevel;
g_return_if_fail (PHOSH_IS_FAVORITES (self));
g_return_if_fail (PHOSH_IS_APP (app));
g_return_if_fail (PHOSH_IS_ACTIVITY (activity));
toplevel = g_object_get_data(G_OBJECT (app), "toplevel");
toplevel = g_object_get_data(G_OBJECT (activity), "toplevel");
g_return_if_fail (PHOSH_IS_TOPLEVEL (toplevel));
g_debug("Will close %s (%s)",
phosh_app_get_app_id (app),
phosh_app_get_title (app));
phosh_activity_get_app_id (activity),
phosh_activity_get_title (activity));
phosh_toplevel_close (toplevel);
g_signal_emit(self, signals[APP_CLOSED], 0);
g_signal_emit(self, signals[ACTIVITY_CLOSED], 0);
}
static void
on_toplevel_closed (PhoshToplevel *toplevel, PhoshApp *app)
on_toplevel_closed (PhoshToplevel *toplevel, PhoshActivity *activity)
{
g_return_if_fail (PHOSH_IS_TOPLEVEL (toplevel));
g_return_if_fail (PHOSH_IS_APP (app));
gtk_widget_destroy (GTK_WIDGET (app));
g_return_if_fail (PHOSH_IS_ACTIVITY (activity));
gtk_widget_destroy (GTK_WIDGET (activity));
}
static void add_app (PhoshFavorites *self, PhoshToplevel *toplevel)
static void add_activity (PhoshFavorites *self, PhoshToplevel *toplevel)
{
PhoshMonitor *monitor = phosh_shell_get_primary_monitor (phosh_shell_get_default ());
PhoshFavoritesPrivate *priv;
GtkWidget *app;
GtkWidget *activity;
int max_width = 0;
const gchar *app_id, *title;
......@@ -118,32 +118,32 @@ static void add_app (PhoshFavorites *self, PhoshToplevel *toplevel)
title = phosh_toplevel_get_title (toplevel);
g_debug ("Building activator for '%s' (%s)", app_id, title);
app = phosh_app_new (app_id, title);
g_object_set (app,
activity = phosh_activity_new (app_id, title);
g_object_set (activity,
"win-width", 360, // TODO: Get the real size somehow
"win-height", 640,
"max-height", 445,
"max-width", max_width,
NULL);
g_object_set_data (G_OBJECT(app), "toplevel", toplevel);
gtk_box_pack_end (GTK_BOX (priv->box_running_apps), app, FALSE, FALSE, 0);
gtk_widget_show (app);
g_object_set_data (G_OBJECT(activity), "toplevel", toplevel);
gtk_box_pack_end (GTK_BOX (priv->box_running_activities), activity, FALSE, FALSE, 0);
gtk_widget_show (activity);
g_signal_connect_swapped (app, "clicked", G_CALLBACK (on_app_clicked), self);
g_signal_connect_swapped (app, "app-closed", G_CALLBACK (on_app_closed), self);
g_signal_connect_swapped (activity, "clicked", G_CALLBACK (on_activity_clicked), self);
g_signal_connect_swapped (activity, "activity-closed", G_CALLBACK (on_activity_closed), self);
g_signal_connect_object (toplevel, "closed", G_CALLBACK (on_toplevel_closed), app, 0);
g_signal_connect_object (toplevel, "closed", G_CALLBACK (on_toplevel_closed), activity, 0);
}
static void
get_running_apps (PhoshFavorites *self)
get_running_activities (PhoshFavorites *self)
{
PhoshToplevelManager *toplevel_manager = phosh_shell_get_toplevel_manager (phosh_shell_get_default ());
guint toplevels_num = phosh_toplevel_manager_get_num_toplevels (toplevel_manager);
for (guint i = 0; i < toplevels_num; i++) {
PhoshToplevel *toplevel = phosh_toplevel_manager_get_toplevel (toplevel_manager, i);
add_app (self, toplevel);
add_activity (self, toplevel);
}
}
......@@ -153,7 +153,7 @@ toplevel_added_cb (PhoshFavorites *self, PhoshToplevel *toplevel, PhoshToplevelM
g_return_if_fail (PHOSH_IS_FAVORITES (self));
g_return_if_fail (PHOSH_IS_TOPLEVEL (toplevel));
g_return_if_fail (PHOSH_IS_TOPLEVEL_MANAGER (manager));
add_app (self, toplevel);
add_activity (self, toplevel);
}
......@@ -163,7 +163,7 @@ set_max_height (GtkWidget *widget,
{
int height = GPOINTER_TO_INT (user_data);
if (!PHOSH_IS_APP (widget)) {
if (!PHOSH_IS_ACTIVITY (widget)) {
return;
}
......@@ -173,7 +173,7 @@ set_max_height (GtkWidget *widget,
}
static void
running_apps_resized (GtkWidget *widget,
running_activities_resized (GtkWidget *widget,
GtkAllocation *alloc,
gpointer data)
{
......@@ -181,7 +181,7 @@ running_apps_resized (GtkWidget *widget,
PhoshFavoritesPrivate *priv = phosh_favorites_get_instance_private (self);
int height = alloc->height * 0.8;
gtk_container_foreach (GTK_CONTAINER (priv->box_running_apps),
gtk_container_foreach (GTK_CONTAINER (priv->box_running_activities),
set_max_height,
GINT_TO_POINTER (height));
}
......@@ -196,7 +196,7 @@ favorite_clicked_cb (GtkWidget *widget,
self = g_object_get_data (G_OBJECT (widget), "favorites");
g_assert (self);
g_signal_emit (self, signals[APP_LAUNCHED], 0);
g_signal_emit (self, signals[ACTIVITY_LAUNCHED], 0);
}
......@@ -301,20 +301,20 @@ phosh_favorites_constructed (GObject *object)
favorites_changed (priv->settings, "favorites", self);
/* Close on click */
g_signal_connect_swapped (priv->evbox_running_apps, "button_press_event",
g_signal_connect_swapped (priv->evbox_running_activities, "button_press_event",
G_CALLBACK (evbox_button_press_event_cb),
self);
gtk_widget_set_events (priv->evbox_running_apps, GDK_BUTTON_PRESS_MASK);
get_running_apps (self);
gtk_widget_set_events (priv->evbox_running_activities, GDK_BUTTON_PRESS_MASK);
get_running_activities (self);
g_signal_connect_object (toplevel_manager, "toplevel-added",
G_CALLBACK (toplevel_added_cb),
self,
G_CONNECT_SWAPPED);
g_signal_connect (priv->evbox_running_apps,
g_signal_connect (priv->evbox_running_activities,
"size-allocate",
G_CALLBACK (running_apps_resized),
G_CALLBACK (running_activities_resized),
self);
}
......@@ -345,19 +345,19 @@ phosh_favorites_class_init (PhoshFavoritesClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, PhoshFavorites, evbox_favorites);
gtk_widget_class_bind_template_child_private (widget_class, PhoshFavorites, fb_favorites);
gtk_widget_class_bind_template_child_private (widget_class, PhoshFavorites, evbox_running_apps);
gtk_widget_class_bind_template_child_private (widget_class, PhoshFavorites, box_running_apps);
gtk_widget_class_bind_template_child_private (widget_class, PhoshFavorites, evbox_running_activities);
gtk_widget_class_bind_template_child_private (widget_class, PhoshFavorites, box_running_activities);