This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch main
in repository widgets.
View the commit online.
commit 9f9d68c456666bec1fd1d921e933e7253ef3b1cd
Author: Alastair Poole <[email protected]>
AuthorDate: Sun Nov 29 04:24:38 2026 +0000
modules: pager
---
README.md | 29 ++-
data/meson.build | 7 +-
data/themes/atelier.edj | Bin 171982 -> 0 bytes
data/themes/build-themes.sh | 8 -
data/themes/crazy_lab.edj | Bin 170638 -> 0 bytes
data/themes/elementary.edj | Bin 172934 -> 0 bytes
data/themes/gadget-desktops.edc | 129 ++++++++++
data/themes/meson.build | 25 ++
data/themes/midnight.edj | Bin 171942 -> 0 bytes
data/themes/observatory.edj | Bin 173286 -> 0 bytes
data/themes/shared.edc | 1 +
e_mod_main.c | 48 ++--
modules/desktops/desktops.c | 530 ++++++++++++++++++++++++++++++++++++++++
modules/desktops/desktops.h | 16 ++
modules/meson.build | 3 +-
modules/widgets_gadgets.c | 3 +
widgets_private.h | 2 +
widgets_settings.c | 1 +
18 files changed, 761 insertions(+), 41 deletions(-)
diff --git a/README.md b/README.md
index 1bbd7c5..02b9c59 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,8 @@ Widgets is an Enlightenment module.
## Build and install
The build needs Meson, Ninja, the Enlightenment and EFL development files,
-and json-c. The gadget code, compiled Edje themes,
-and weather icons and place catalog are included in this repository.
+json-c, and the Edje compiler (`edje_cc`). The repository includes the gadget
+code, theme sources, weather icons, and place catalog.
```sh
meson setup build
@@ -29,12 +29,9 @@ Atelier, Crazy Lab, Elementary, and Midnight. The choice applies immediately
and is saved with your gadget preferences. The Settings window uses the default
Elementary theme.
-The theme sources and bundled Edje files live in `data/themes/`. Meson installs
-the Edje files. To rebuild all five after editing the sources, run:
-
-```sh
-sh data/themes/build-themes.sh
-```
+The theme sources live in `data/themes/`. Meson compiles all five themes into
+the build directory and installs the generated Edje files. To rebuild after
+editing a theme, run `meson compile -C build`.
The artwork and gadget sources retain their authorship of the software developer.
@@ -52,3 +49,19 @@ notes. Select **Add note** in Settings or press **+** on a note to create anothe
Drag the bottom-right handle on a note or the System Logs card to resize it.
Visibility, positions, sizes, and gadget preferences are saved in
`${XDG_CONFIG_HOME:-~/.config}/widgets/gadgets.ini`.
+
+### Virtual Desktops
+
+Turn on **Show virtual desktops gadget** in Widget Settings. Click a tile to
+switch to that desktop. The highlighted tile is the current desktop, and
+each preview uses Enlightenment’s pager to show live window contents and the
+desktop’s configured wallpaper. On a multi-monitor setup, the gadget shows
+the desktops for the monitor it sits on.
+
+Set **Columns** and **Rows**, then select **Apply virtual desktop layout** to
+update Enlightenment's desktop grid across all monitors. Use one row for a
+horizontal strip or one column for a vertical strip.
+
+Drag the top border to move the gadget. Hover over its bottom-right corner to
+reveal the resize grip, then drag it to scale the grid while keeping each
+preview in the monitor’s aspect ratio.
diff --git a/data/meson.build b/data/meson.build
index 5fabf28..b0380a1 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,7 +1,2 @@
-install_data(
- 'themes/observatory.edj', 'themes/atelier.edj', 'themes/crazy_lab.edj',
- 'themes/elementary.edj', 'themes/midnight.edj',
- install_dir: module_dir / 'themes',
- install_mode: 'rw-r--r--',
-)
+subdir('themes')
install_subdir('weather', install_dir: module_dir / 'gadgets')
diff --git a/data/themes/atelier.edj b/data/themes/atelier.edj
deleted file mode 100644
index 3b413ea..0000000
Binary files a/data/themes/atelier.edj and /dev/null differ
diff --git a/data/themes/build-themes.sh b/data/themes/build-themes.sh
deleted file mode 100644
index 50bbb26..0000000
--- a/data/themes/build-themes.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-set -eu
-cd "$(dirname "$0")"
-for name in observatory atelier crazy_lab elementary midnight; do
- edje_cc -id "$name" -id observatory -id surfaces -id clock -id . \
- -sd "$name" -sd observatory "$name.edc" "$name.edj"
- chmod 0644 "$name.edj"
-done
diff --git a/data/themes/crazy_lab.edj b/data/themes/crazy_lab.edj
deleted file mode 100644
index ce5bd7d..0000000
Binary files a/data/themes/crazy_lab.edj and /dev/null differ
diff --git a/data/themes/elementary.edj b/data/themes/elementary.edj
deleted file mode 100644
index 0b2b550..0000000
Binary files a/data/themes/elementary.edj and /dev/null differ
diff --git a/data/themes/gadget-desktops.edc b/data/themes/gadget-desktops.edc
new file mode 100644
index 0000000..18f6798
--- /dev/null
+++ b/data/themes/gadget-desktops.edc
@@ -0,0 +1,129 @@
+#ifdef THEMED_CONTROLS
+#define DESKTOP_FACE CONTROL_STENCIL
+#define DESKTOP_RADIUS CONTROL_RADIUS
+#define DESKTOP_FONT UI_FONT
+#else
+#define DESKTOP_FACE "../surfaces/curve-12.png"
+#define DESKTOP_RADIUS 12 12 12 12
+#define DESKTOP_FONT "Sans"
+#endif
+
+#define DESKTOP_GRIP(NAME, X, Y) \
+ part { name: NAME; type: RECT; mouse_events: 0; \
+ description { state: "default" 0.0; color: 0 0 0 0; \
+ rel1 { relative: 1 1; offset: X Y; } \
+ rel2 { relative: 1 1; offset: X Y; } \
+ min: 2 2; \
+ } \
+ description { state: "hover" 0.0; inherit: "default" 0.0; color: MUTE; } \
+ }
+
+group { name: "entrance/gadgets/desktops";
+ parts {
+ GADGET_SHADOW(DESKTOP_FACE, DESKTOP_RADIUS)
+ part { name: "rim"; type: IMAGE; mouse_events: 0;
+ description { state: "default" 0.0; color: EDGE;
+ image { normal: DESKTOP_FACE; border: DESKTOP_RADIUS; }
+ }
+ }
+ part { name: "surface"; type: IMAGE; mouse_events: 0;
+ description { state: "default" 0.0; color: WALL;
+ rel1.offset: 1 1; rel2.offset: -2 -2;
+ image { normal: DESKTOP_FACE; border: DESKTOP_RADIUS; }
+ }
+ }
+ part { name: "desktops.drag"; type: RECT;
+ description { state: "default" 0.0; color: 0 0 0 0;
+ rel2 { relative: 1 0; offset: -1 21; }
+ }
+ }
+ part { name: "desktops.grid"; type: SWALLOW;
+ description { state: "default" 0.0;
+ rel1.offset: 10 22; rel2.offset: -11 -11;
+ }
+ }
+ DESKTOP_GRIP("grip.top", -8, -15)
+ DESKTOP_GRIP("grip.middle", -8, -11)
+ DESKTOP_GRIP("grip.left", -12, -7)
+ DESKTOP_GRIP("grip.bottom", -8, -7)
+ part { name: "widgets.resize"; type: RECT;
+ description { state: "default" 0.0; color: 0 0 0 0;
+ rel1 { relative: 1 1; offset: -21 -21; }
+ }
+ }
+ }
+ programs {
+ program { signal: "mouse,in"; source: "widgets.resize";
+ action: STATE_SET "hover" 0.0; transition: LINEAR 0.12;
+ targets: "grip.top" "grip.middle" "grip.left" "grip.bottom";
+ }
+ program { signal: "mouse,out"; source: "widgets.resize";
+ action: STATE_SET "default" 0.0; transition: LINEAR 0.16;
+ targets: "grip.top" "grip.middle" "grip.left" "grip.bottom";
+ }
+ }
+}
+
+group { name: "entrance/gadgets/desktops/tile";
+ parts {
+ part { name: "rim"; type: IMAGE; mouse_events: 0;
+ description { state: "default" 0.0; color: EDGE;
+ rel1.offset: 2 2; rel2.offset: -3 -3;
+ image { normal: DESKTOP_FACE; border: DESKTOP_RADIUS; }
+ }
+ description { state: "active" 0.0; inherit: "default" 0.0; color: ACCENT; }
+ }
+ part { name: "well"; type: IMAGE; mouse_events: 0;
+ description { state: "default" 0.0; color: WELL;
+ rel.to: "rim";
+ rel1.offset: 2 2; rel2.offset: -3 -3;
+ image { normal: DESKTOP_FACE; border: DESKTOP_RADIUS; }
+ }
+ }
+ part { name: "desktop.preview"; type: SWALLOW; mouse_events: 0;
+ description { state: "default" 0.0; rel.to: "well"; }
+ }
+ part { name: "label.clip"; type: RECT; mouse_events: 0;
+ description { state: "default" 0.0; }
+ description { state: "compact" 0.0; visible: 0; }
+ }
+ part { name: "label.background"; type: RECT; mouse_events: 0;
+ clip_to: "label.clip";
+ description { state: "default" 0.0; color: WALL;
+ rel1 { relative: 0 1; offset: 0 -16; to: "well"; }
+ rel2.to: "well";
+ }
+ }
+ part { name: "desktop.name"; type: TEXT; mouse_events: 0; scale: 1;
+ clip_to: "label.clip";
+ description { state: "default" 0.0; color: INK;
+ rel1 { relative: 0 1; offset: 5 -15; to: "well"; }
+ rel2 { offset: -6 -2; to: "well"; }
+ text { font: DESKTOP_FONT; size: 10; align: 0.5 0.5; }
+ }
+ description { state: "active" 0.0; inherit: "default" 0.0; color: ACCENT; }
+ }
+ part { name: "desktop.hit"; type: RECT;
+ description { state: "default" 0.0; color: 0 0 0 0; rel.to: "rim"; }
+ }
+ }
+ programs {
+ program { signal: "desktop,compact"; source: "widgets";
+ action: STATE_SET "compact" 0.0; target: "label.clip";
+ }
+ program { signal: "desktop,full"; source: "widgets";
+ action: STATE_SET "default" 0.0; target: "label.clip";
+ }
+ program { signal: "desktop,active"; source: "widgets";
+ action: STATE_SET "active" 0.0; targets: "rim" "desktop.name";
+ }
+ program { signal: "desktop,inactive"; source: "widgets";
+ action: STATE_SET "default" 0.0; targets: "rim" "desktop.name";
+ }
+ }
+}
+
+#undef DESKTOP_GRIP
+#undef DESKTOP_FACE
+#undef DESKTOP_RADIUS
+#undef DESKTOP_FONT
diff --git a/data/themes/meson.build b/data/themes/meson.build
new file mode 100644
index 0000000..34ac176
--- /dev/null
+++ b/data/themes/meson.build
@@ -0,0 +1,25 @@
+edje_cc = find_program('edje_cc')
+theme_source_dir = meson.current_source_dir()
+
+foreach theme : ['observatory', 'atelier', 'crazy_lab', 'elementary', 'midnight']
+ custom_target(
+ theme + '.edj',
+ input: theme + '.edc',
+ output: theme + '.edj',
+ depfile: theme + '.d',
+ command: [
+ edje_cc, '-deps', '@DEPFILE@',
+ '-id', theme_source_dir / theme,
+ '-id', theme_source_dir / 'observatory',
+ '-id', theme_source_dir / 'surfaces',
+ '-id', theme_source_dir / 'clock',
+ '-id', theme_source_dir,
+ '-sd', theme_source_dir / theme,
+ '-sd', theme_source_dir / 'observatory',
+ '@INPUT@', '@OUTPUT@',
+ ],
+ install: true,
+ install_dir: module_dir / 'themes',
+ install_mode: 'rw-r--r--',
+ )
+endforeach
diff --git a/data/themes/midnight.edj b/data/themes/midnight.edj
deleted file mode 100644
index 6a46592..0000000
Binary files a/data/themes/midnight.edj and /dev/null differ
diff --git a/data/themes/observatory.edj b/data/themes/observatory.edj
deleted file mode 100644
index e96051e..0000000
Binary files a/data/themes/observatory.edj and /dev/null differ
diff --git a/data/themes/shared.edc b/data/themes/shared.edc
index 7d73a40..cc3ee43 100644
--- a/data/themes/shared.edc
+++ b/data/themes/shared.edc
@@ -108,6 +108,7 @@ collections {
#include "gadget-sysinfo.edc"
#include "gadget-music.edc"
#include "gadget-logger.edc"
+ #include "gadget-desktops.edc"
#include "gadget-daylight.edc"
#include "gadget-sports.edc"
#include "gadget-updates.edc"
diff --git a/e_mod_main.c b/e_mod_main.c
index fccdaf2..5e71f2b 100644
--- a/e_mod_main.c
+++ b/e_mod_main.c
@@ -71,7 +71,7 @@ widgets_shape_update(void *data)
rects = g_new(Ecore_X_Rectangle, eina_list_count(state->cards) + 1);
EINA_LIST_FOREACH(state->cards, l, card)
{
- if (!evas_object_visible_get(card)) continue;
+ if (evas_object_evas_get(card) == e_comp->evas || !evas_object_visible_get(card)) continue;
evas_object_geometry_get(card, &x, &y, &w, &h);
if ((w <= 0) || (h <= 0)) continue;
rects[count++] = (Ecore_X_Rectangle){ x, y, w, h };
@@ -90,21 +90,23 @@ widgets_shape_queue(Widgets *state)
}
static void
-widgets_card_changed(void *data, Evas *evas EINA_UNUSED, Evas_Object *card EINA_UNUSED,
+widgets_card_changed(void *data, Evas *evas, Evas_Object *card EINA_UNUSED,
void *event EINA_UNUSED)
{
- widgets_shape_queue(data);
+ if (evas == e_comp->evas) e_comp_shape_queue();
+ else widgets_shape_queue(data);
}
static void
-widgets_card_deleted(void *data, Evas *evas EINA_UNUSED, Evas_Object *card,
+widgets_card_deleted(void *data, Evas *evas, Evas_Object *card,
void *event EINA_UNUSED)
{
Widgets *state;
state = data;
state->cards = eina_list_remove(state->cards, card);
- widgets_shape_queue(state);
+ if (evas == e_comp->evas) e_comp_shape_queue();
+ else widgets_shape_queue(state);
}
static void
@@ -125,32 +127,42 @@ widgets_menu_settings(void *data, E_Menu *menu EINA_UNUSED,
}
static void
-widgets_card_menu(void *data, Evas *evas EINA_UNUSED, Evas_Object *card EINA_UNUSED,
- void *event)
+widgets_card_menu(void *data, Evas *evas, Evas_Object *card EINA_UNUSED, void *event)
{
- Widgets *state;
- Evas_Event_Mouse_Up *mouse;
+ Widgets *state = data;
+ Evas_Event_Mouse_Down *mouse = event;
E_Menu_Item *item;
E_Zone *zone;
+ int x, y, direction;
- state = data;
- mouse = event;
- if ((mouse->button != 3) || state->menu) return;
+ if (mouse->button != 3 || state->menu) return;
- zone = e_zone_current_get();
+ ecore_x_pointer_xy_get(e_comp->root, &x, &y);
+ x = e_comp_canvas_x_root_adjust(x);
+ y = e_comp_canvas_y_root_adjust(y);
+ zone = e_comp_zone_xy_get(x, y);
if (!zone) return;
state->menu = e_menu_new();
if (!state->menu) return;
+ e_menu_hold_mode_set(state->menu, EINA_FALSE);
e_menu_post_deactivate_callback_set(state->menu, widgets_menu_closed, state);
item = e_menu_item_new(state->menu);
e_menu_item_label_set(item, "Widget Settings");
e_menu_item_icon_file_set(item, "preferences-desktop");
e_menu_item_callback_set(item, widgets_menu_settings, state);
- e_menu_activate(state->menu, zone, mouse->output.x, mouse->output.y,
- 1, 1, E_MENU_POP_DIRECTION_AUTO);
- if (state->menu && !state->menu->active) widgets_menu_closed(state, state->menu);
+
+ direction = y < zone->y + zone->h / 2 ? E_MENU_POP_DIRECTION_DOWN : E_MENU_POP_DIRECTION_UP;
+ e_menu_activate_mouse(state->menu, zone, x, y, 1, 1, direction, mouse->timestamp);
+ if (!state->menu) return;
+ if (!state->menu->active)
+ {
+ widgets_menu_closed(state, state->menu);
+ return;
+ }
+
mouse->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+ evas_event_feed_mouse_up(evas, mouse->button, EVAS_BUTTON_NONE, mouse->timestamp, NULL);
}
void
@@ -257,7 +269,7 @@ widgets_card_register(Evas_Object *card)
evas_object_event_callback_add(card, EVAS_CALLBACK_SHOW, widgets_card_changed, state);
evas_object_event_callback_add(card, EVAS_CALLBACK_HIDE, widgets_card_changed, state);
evas_object_event_callback_add(card, EVAS_CALLBACK_DEL, widgets_card_deleted, state);
- evas_object_event_callback_add(card, EVAS_CALLBACK_MOUSE_UP, widgets_card_menu, state);
+ evas_object_event_callback_add(card, EVAS_CALLBACK_MOUSE_DOWN, widgets_card_menu, state);
widgets_shape_queue(state);
}
@@ -456,7 +468,7 @@ widgets_any_enabled(GKeyFile *config)
{
static const char *const groups[] =
{
- "clock", "daylight", "logger", "music", "notes",
+ "clock", "daylight", "desktops", "logger", "music", "notes",
"sports", "sysinfo", "updates", "Weather"
};
unsigned int i;
diff --git a/modules/desktops/desktops.c b/modules/desktops/desktops.c
new file mode 100644
index 0000000..14fe0b3
--- /dev/null
+++ b/modules/desktops/desktops.c
@@ -0,0 +1,530 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <e.h>
+#include <math.h>
+
+#include "widgets_private.h"
+#include "widgets_i18n.h"
+
+#define DESKTOPS_SETTINGS "desktops"
+#define DESKTOPS_GROUP "entrance/gadgets/desktops"
+#define DEFAULT_X 0.78
+#define DEFAULT_Y 0.72
+/* Match the grid and tile insets in gadget-desktops.edc. */
+#define GRID_INSET_X 20
+#define GRID_INSET_Y 32
+#define TILE_INSET 8
+
+typedef struct
+{
+ Widgets_Desktops *owner;
+ Evas_Object *face, *preview;
+ int column, row;
+} Desktop_Tile;
+
+struct Widgets_Desktops
+{
+ Evas_Object *bounds, *layout, *grid;
+ GKeyFile *settings;
+ Eina_Bool (*save)(void *data);
+ void *save_data;
+ char *theme;
+ double x, y;
+ int grab_x, grab_y, width, height;
+ Widgets_Card_Resize resize;
+ Eina_Bool dragging;
+ Ecore_Job *refresh;
+ Ecore_Event_Handler *handlers[6];
+ E_Zone *zone;
+ GArray *tiles;
+ int columns, rows, zone_width, zone_height;
+};
+
+static E_Zone *
+_zone(Widgets_Desktops *desktops)
+{
+ int x, y, width, height;
+
+ evas_object_geometry_get(desktops->layout, &x, &y, &width, &height);
+ E_Zone *zone = e_comp_zone_xy_get(x + width / 2, y + height / 2);
+ return zone ? zone : e_zone_current_get();
+}
+
+static double
+_scale_for_size(const E_Zone *zone, int width, int height)
+{
+ double content_width = width - GRID_INSET_X - (double)zone->desk_x_count * TILE_INSET;
+ double content_height = height - GRID_INSET_Y - (double)zone->desk_y_count * TILE_INSET;
+
+ return MAX(0.0, MIN(content_width / ((double)zone->desk_x_count * zone->w),
+ content_height / ((double)zone->desk_y_count * zone->h)));
+}
+
+static void
+_size_fit(const E_Zone *zone, double scale, int max_width, int max_height,
+ int *width, int *height)
+{
+ double max_scale = _scale_for_size(zone, max_width, max_height);
+ double min_scale = MIN(max_scale, MAX(40.0 / zone->w, 26.0 / zone->h));
+
+ scale = CLAMP(scale, min_scale, max_scale);
+ *width = MIN(max_width, GRID_INSET_X +
+ lround(zone->desk_x_count * (TILE_INSET + scale * zone->w)));
+ *height = MIN(max_height, GRID_INSET_Y +
+ lround(zone->desk_y_count * (TILE_INSET + scale * zone->h)));
+}
+
+static void
+_switch(void *data, Evas_Object *object EINA_UNUSED,
+ const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
+{
+ Desktop_Tile *tile = data;
+ E_Zone *zone = _zone(tile->owner);
+ E_Desk *desk = zone ? e_desk_at_xy_get(zone, tile->column, tile->row) : NULL;
+
+ if (desk)
+ e_desk_show(desk);
+}
+
+static void
+_tile_resize(void *data EINA_UNUSED, Evas *canvas EINA_UNUSED, Evas_Object *object,
+ void *event EINA_UNUSED)
+{
+ int width, height;
+
+ evas_object_geometry_get(object, NULL, NULL, &width, &height);
+ edje_object_signal_emit(object, width < 55 || height < 45
+ ? "desktop,compact" : "desktop,full", "widgets");
+}
+
+static void
+_preview_deleted(void *data, Evas *canvas EINA_UNUSED, Evas_Object *object EINA_UNUSED,
+ void *event EINA_UNUSED)
+{
+ Desktop_Tile *tile = data;
+
+ tile->preview = NULL;
+}
+
+static void
+_tiles_clear(Widgets_Desktops *desktops)
+{
+ for (unsigned int i = 0; i < desktops->tiles->len; i++)
+ {
+ Desktop_Tile *tile = &g_array_index(desktops->tiles, Desktop_Tile, i);
+ if (!tile->preview)
+ continue;
+ evas_object_event_callback_del_full(tile->preview, EVAS_CALLBACK_DEL,
+ _preview_deleted, tile);
+ evas_object_del(tile->preview);
+ }
+ evas_object_grid_clear(desktops->grid, EINA_TRUE);
+ g_array_set_size(desktops->tiles, 0);
+}
+
+static void
+_tiles_build(Widgets_Desktops *desktops, E_Zone *zone)
+{
+ Evas *canvas = evas_object_evas_get(desktops->grid);
+ int columns = zone->desk_x_count;
+ int rows = zone->desk_y_count;
+
+ _tiles_clear(desktops);
+ g_array_set_size(desktops->tiles, columns * rows);
+ desktops->zone = zone;
+ desktops->zone_width = zone->w;
+ desktops->zone_height = zone->h;
+ desktops->columns = columns;
+ desktops->rows = rows;
+ evas_object_grid_size_set(desktops->grid, columns * 100, rows * 100);
+ for (int row = 0; row < rows; row++)
+ for (int column = 0; column < columns; column++)
+ {
+ Desktop_Tile *tile = &g_array_index(desktops->tiles, Desktop_Tile,
+ row * columns + column);
+ *tile = (Desktop_Tile){ .owner = desktops, .column = column, .row = row };
+ tile->face = edje_object_add(canvas);
+ edje_object_file_set(tile->face, desktops->theme, DESKTOPS_GROUP "/tile");
+ evas_object_event_callback_add(tile->face, EVAS_CALLBACK_RESIZE, _tile_resize, NULL);
+ E_Desk *desk = e_desk_at_xy_get(zone, column, row);
+ if (desk)
+ {
+ tile->preview = e_deskmirror_add(desk, EINA_TRUE, EINA_FALSE);
+ if (tile->preview)
+ {
+ evas_object_event_callback_add(tile->preview, EVAS_CALLBACK_DEL,
+ _preview_deleted, tile);
+ evas_object_pass_events_set(tile->preview, EINA_TRUE);
+ edje_object_part_swallow(tile->face, "desktop.preview", tile->preview);
+ evas_object_show(tile->preview);
+ }
+ }
+ edje_object_signal_callback_add(tile->face, "mouse,clicked,1", "desktop.hit",
+ _switch, tile);
+ evas_object_grid_pack(desktops->grid, tile->face, column * 100, row * 100, 100, 100);
+ evas_object_show(tile->face);
+ }
+}
+
+static void
+_refresh(void *data)
+{
+ Widgets_Desktops *desktops = data;
+ E_Zone *zone = _zone(desktops);
+
+ desktops->refresh = NULL;
+ if (!zone || zone->w <= 0 || zone->h <= 0 ||
+ zone->desk_x_count < 1 || zone->desk_y_count < 1)
+ {
+ _tiles_clear(desktops);
+ desktops->zone = NULL;
+ evas_object_hide(desktops->grid);
+ return;
+ }
+ evas_object_show(desktops->grid);
+ if (desktops->zone != zone ||
+ desktops->columns != zone->desk_x_count || desktops->rows != zone->desk_y_count ||
+ desktops->zone_width != zone->w || desktops->zone_height != zone->h)
+ {
+ int x, y, width, height;
+ double scale = _scale_for_size(zone, desktops->width, desktops->height);
+
+ _size_fit(zone, scale, zone->w, zone->h, &width, &height);
+ evas_object_geometry_get(desktops->layout, &x, &y, NULL, NULL);
+ evas_object_resize(desktops->layout, width, height);
+ evas_object_move(desktops->layout, CLAMP(x, zone->x, zone->x + zone->w - width),
+ CLAMP(y, zone->y, zone->y + zone->h - height));
+ _tiles_build(desktops, zone);
+ }
+
+ E_Desk *current = e_desk_current_get(zone);
+ for (unsigned int i = 0; i < desktops->tiles->len; i++)
+ {
+ Desktop_Tile *tile = &g_array_index(desktops->tiles, Desktop_Tile, i);
+ E_Desk *desk = e_desk_at_xy_get(zone, tile->column, tile->row);
+ if (!desk)
+ continue;
+ edje_object_part_text_set(tile->face, "desktop.name", desk->name);
+ edje_object_signal_emit(tile->face, desk == current ? "desktop,active" : "desktop,inactive",
+ "widgets");
+ }
+}
+
+static void
+_refresh_queue(Widgets_Desktops *desktops)
+{
+ if (!desktops->refresh)
+ desktops->refresh = ecore_job_add(_refresh, desktops);
+}
+
+static Eina_Bool
+_desktop_changed(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
+{
+ _refresh_queue(data);
+ return ECORE_CALLBACK_RENEW;
+}
+
+static void
+_card_moved(void *data, Evas *canvas EINA_UNUSED, Evas_Object *object EINA_UNUSED,
+ void *event EINA_UNUSED)
+{
+ _refresh_queue(data);
+}
+
+static void
+_apply_theme(Widgets_Desktops *desktops)
+{
+ edje_object_file_set(desktops->layout, desktops->theme, DESKTOPS_GROUP);
+ edje_object_part_swallow(desktops->layout, "desktops.grid", desktops->grid);
+ desktops->columns = 0;
+ _refresh_queue(desktops);
+}
+
+static void
+_place(Widgets_Desktops *desktops)
+{
+ Evas_Coord x, y, width, height;
+ int card_width, card_height;
+
+ if (!desktops->layout)
+ return;
+
+ evas_object_geometry_get(desktops->bounds, &x, &y, &width, &height);
+ if (width <= 0 || height <= 0)
+ return;
+
+ E_Zone *zone = _zone(desktops);
+ if (zone && zone->w > 0 && zone->h > 0 && zone->desk_x_count > 0 && zone->desk_y_count > 0)
+ {
+ double scale = _scale_for_size(zone, desktops->width, desktops->height);
+ _size_fit(zone, scale, zone->w, zone->h, &card_width, &card_height);
+ }
+ else
+ {
+ card_width = MIN(width, desktops->width);
+ card_height = MIN(height, desktops->height);
+ }
+ evas_object_resize(desktops->layout, card_width, card_height);
+ widgets_card_place(desktops->layout, x + lround(desktops->x * (width - card_width)),
+ y + lround(desktops->y * (height - card_height)));
+}
+
+static void
+_resize(void *data, Evas *canvas EINA_UNUSED, Evas_Object *object EINA_UNUSED,
+ void *event EINA_UNUSED)
+{
+ _place(data);
+}
+
+static void
+_drag_start(void *data, Evas *canvas EINA_UNUSED, Evas_Object *object, void *event)
+{
+ Widgets_Desktops *desktops = data;
+ Evas_Event_Mouse_Down *mouse = event;
+ Evas_Coord x, y, header_w, header_h;
+
+ if (mouse->button != 1)
+ return;
+ if (widgets_card_resize_start(&desktops->resize, object, object, mouse))
+ return;
+ if (!edje_object_part_geometry_get(object, "desktops.drag",
+ NULL, NULL, &header_w, &header_h))
+ return;
+
+ evas_object_geometry_get(object, &x, &y, NULL, NULL);
+ desktops->grab_x = mouse->canvas.x - x;
+ desktops->grab_y = mouse->canvas.y - y;
+ desktops->dragging = desktops->grab_x >= 0 && desktops->grab_x < header_w &&
+ desktops->grab_y >= 0 && desktops->grab_y < header_h;
+}
+
+static void
+_drag_move(void *data, Evas *canvas EINA_UNUSED, Evas_Object *object, void *event)
+{
+ Widgets_Desktops *desktops = data;
+ Evas_Event_Mouse_Move *mouse = event;
+
+ if (desktops->resize.active)
+ {
+ E_Zone *zone = _zone(desktops);
+ if (!zone || zone != desktops->zone || zone->w <= 0 || zone->h <= 0 ||
+ zone->desk_x_count != desktops->columns || zone->desk_y_count != desktops->rows)
+ return;
+
+ const Widgets_Card_Resize *resize = &desktops->resize;
+ double grid_width = (double)zone->desk_x_count * zone->w;
+ double grid_height = (double)zone->desk_y_count * zone->h;
+ double dx = mouse->cur.canvas.x - resize->pointer_x;
+ double dy = mouse->cur.canvas.y - resize->pointer_y;
+ double scale = _scale_for_size(zone, resize->width, resize->height);
+ scale += (dx * grid_width + dy * grid_height) /
+ (grid_width * grid_width + grid_height * grid_height);
+ _size_fit(zone, scale, resize->max_width, resize->max_height,
+ &desktops->width, &desktops->height);
+ evas_object_resize(object, desktops->width, desktops->height);
+ }
+ else if (desktops->dragging)
+ widgets_card_place(object, mouse->cur.canvas.x - desktops->grab_x,
+ mouse->cur.canvas.y - desktops->grab_y);
+}
+
+static void
+_drag_end(void *data, Evas *canvas EINA_UNUSED, Evas_Object *object, void *event)
+{
+ Widgets_Desktops *desktops = data;
+ Evas_Event_Mouse_Up *mouse = event;
+
+ if ((!desktops->dragging && !desktops->resize.active) || mouse->button != 1)
+ return;
+
+ if (desktops->resize.active)
+ {
+ g_key_file_set_integer(desktops->settings, DESKTOPS_SETTINGS, "width", desktops->width);
+ g_key_file_set_integer(desktops->settings, DESKTOPS_SETTINGS, "height", desktops->height);
+ }
+ widgets_card_position_store(object, desktops->bounds, &desktops->x, &desktops->y);
+ desktops->resize.active = EINA_FALSE;
+ desktops->dragging = EINA_FALSE;
+ g_key_file_set_double(desktops->settings, DESKTOPS_SETTINGS, "x", desktops->x);
+ g_key_file_set_double(desktops->settings, DESKTOPS_SETTINGS, "y", desktops->y);
+ desktops->save(desktops->save_data);
+}
+
+static void
+_start(Widgets_Desktops *desktops)
+{
+ if (desktops->layout || !desktops->theme)
+ return;
+
+ /* The pager mirrors can only be swallowed by an object on the compositor canvas. */
+ desktops->layout = edje_object_add(e_comp->evas);
+ widgets_card_register(desktops->layout);
+ evas_object_layer_set(desktops->layout, E_LAYER_DESKTOP_TOP);
+ evas_object_event_callback_add(desktops->layout, EVAS_CALLBACK_MOVE, _card_moved, desktops);
+ evas_object_event_callback_add(desktops->layout, EVAS_CALLBACK_MOUSE_DOWN, _drag_start, desktops);
+ evas_object_event_callback_add(desktops->layout, EVAS_CALLBACK_MOUSE_MOVE, _drag_move, desktops);
+ evas_object_event_callback_add(desktops->layout, EVAS_CALLBACK_MOUSE_UP, _drag_end, desktops);
+
+ desktops->tiles = g_array_new(FALSE, FALSE, sizeof(Desktop_Tile));
+ desktops->grid = evas_object_grid_add(evas_object_evas_get(desktops->layout));
+ _place(desktops);
+ _apply_theme(desktops);
+ evas_object_show(desktops->layout);
+ const int events[] = { E_EVENT_DESK_SHOW, E_EVENT_DESK_NAME_CHANGE, E_EVENT_ZONE_DESK_COUNT_SET,
+ E_EVENT_ZONE_MOVE_RESIZE, E_EVENT_ZONE_ADD, E_EVENT_ZONE_DEL };
+ for (unsigned int i = 0; i < EINA_C_ARRAY_LENGTH(events); i++)
+ desktops->handlers[i] = ecore_event_handler_add(events[i], _desktop_changed, desktops);
+}
+
+static void
+_stop(Widgets_Desktops *desktops)
+{
+ if (!desktops->layout)
+ return;
+
+ for (unsigned int i = 0; i < EINA_C_ARRAY_LENGTH(desktops->handlers); i++)
+ ecore_event_handler_del(desktops->handlers[i]);
+ if (desktops->refresh)
+ {
+ ecore_job_del(desktops->refresh);
+ desktops->refresh = NULL;
+ }
+ _tiles_clear(desktops);
+ evas_object_del(desktops->grid);
+ evas_object_del(desktops->layout);
+ g_array_free(desktops->tiles, TRUE);
+ desktops->layout = NULL;
+ desktops->resize.active = EINA_FALSE;
+ desktops->dragging = EINA_FALSE;
+}
+
+static double
+_position(GKeyFile *settings, const char *key, double fallback)
+{
+ g_autoptr(GError) error = NULL;
+ double value = g_key_file_get_double(settings, DESKTOPS_SETTINGS, key, &error);
+
+ return !error && value >= 0 && value <= 1 ? value : fallback;
+}
+
+Widgets_Desktops *
+widgets_desktops_new(Evas_Object *bounds, GKeyFile *settings,
+ Eina_Bool (*save)(void *data), void *data)
+{
+ Widgets_Desktops *desktops = g_new0(Widgets_Desktops, 1);
+
+ desktops->bounds = bounds;
+ desktops->settings = settings;
+ desktops->save = save;
+ desktops->save_data = data;
+ desktops->x = _position(settings, "x", DEFAULT_X);
+ desktops->y = _position(settings, "y", DEFAULT_Y);
+ desktops->width = g_key_file_get_integer(settings, DESKTOPS_SETTINGS, "width", NULL);
+ desktops->height = g_key_file_get_integer(settings, DESKTOPS_SETTINGS, "height", NULL);
+ desktops->width = desktops->width > 0 ? desktops->width : 380;
+ desktops->height = desktops->height > 0 ? desktops->height : 230;
+ evas_object_event_callback_add(bounds, EVAS_CALLBACK_MOVE, _resize, desktops);
+ evas_object_event_callback_add(bounds, EVAS_CALLBACK_RESIZE, _resize, desktops);
+ return desktops;
+}
+
+void
+widgets_desktops_theme_set(Widgets_Desktops *desktops, const char *file)
+{
+ if (!desktops)
+ return;
+ if (file)
+ {
+ g_free(desktops->theme);
+ desktops->theme = g_strdup(file);
+ }
+ if (desktops->layout && file)
+ _apply_theme(desktops);
+ else if (!desktops->layout &&
+ g_key_file_get_boolean(desktops->settings, DESKTOPS_SETTINGS, "enabled", NULL))
+ _start(desktops);
+}
+
+static void
+_toggle(void *data, Evas_Object *object, void *event EINA_UNUSED)
+{
+ Widgets_Desktops *desktops = data;
+ Eina_Bool enabled = elm_check_state_get(object);
+
+ g_key_file_set_boolean(desktops->settings, DESKTOPS_SETTINGS, "enabled", enabled);
+ if (enabled)
+ _start(desktops);
+ else
+ _stop(desktops);
+ if (!desktops->save(desktops->save_data))
+ elm_object_text_set(object, _("Could not save the virtual desktops gadget settings."));
+}
+
+static void
+_grid_apply(void *data, Evas_Object *button, void *event EINA_UNUSED)
+{
+ Evas_Object *columns = data;
+ Evas_Object *rows = evas_object_data_get(button, "rows");
+ Eina_List *item;
+ E_Zone *zone;
+ int width = lround(elm_spinner_value_get(columns));
+ int height = lround(elm_spinner_value_get(rows));
+
+ EINA_LIST_FOREACH(e_comp->zones, item, zone)
+ e_zone_desk_count_set(zone, width, height);
+}
+
+static Evas_Object *
+_grid_dimension_add(Evas_Object *box, const char *label, int value)
+{
+ Evas_Object *spinner = elm_spinner_add(box);
+
+ elm_spinner_min_max_set(spinner, 1, 12);
+ elm_spinner_step_set(spinner, 1);
+ elm_spinner_round_set(spinner, 1);
+ elm_spinner_label_format_set(spinner, label);
+ elm_spinner_value_set(spinner, value);
+ evas_object_size_hint_weight_set(spinner, EVAS_HINT_EXPAND, 0);
+ evas_object_size_hint_align_set(spinner, EVAS_HINT_FILL, 0.5);
+ elm_box_pack_end(box, spinner);
+ evas_object_show(spinner);
+ return spinner;
+}
+
+void
+widgets_desktops_controls_add(Widgets_Desktops *desktops, Evas_Object *box)
+{
+ Evas_Object *check = elm_check_add(box);
+
+ elm_object_text_set(check, _("Show virtual desktops gadget"));
+ elm_check_state_set(check, g_key_file_get_boolean(desktops->settings, DESKTOPS_SETTINGS,
+ "enabled", NULL));
+ evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0);
+ evas_object_size_hint_align_set(check, EVAS_HINT_FILL, 0.5);
+ evas_object_smart_callback_add(check, "changed", _toggle, desktops);
+ elm_box_pack_end(box, check);
+ evas_object_show(check);
+
+ Evas_Object *columns = _grid_dimension_add(box, _("Columns %.0f"),
+ e_config->zone_desks_x_count);
+ Evas_Object *rows = _grid_dimension_add(box, _("Rows %.0f"),
+ e_config->zone_desks_y_count);
+ Evas_Object *apply = elm_button_add(box);
+ elm_object_text_set(apply, _("Apply virtual desktop layout"));
+ evas_object_data_set(apply, "rows", rows);
+ evas_object_smart_callback_add(apply, "clicked", _grid_apply, columns);
+ evas_object_size_hint_align_set(apply, EVAS_HINT_FILL, 0.5);
+ elm_box_pack_end(box, apply);
+ evas_object_show(apply);
+}
+
+void
+widgets_desktops_free(Widgets_Desktops *desktops)
+{
+ if (!desktops)
+ return;
+ evas_object_event_callback_del_full(desktops->bounds, EVAS_CALLBACK_MOVE, _resize, desktops);
+ evas_object_event_callback_del_full(desktops->bounds, EVAS_CALLBACK_RESIZE, _resize, desktops);
+ _stop(desktops);
+ g_free(desktops->theme);
+ g_free(desktops);
+}
diff --git a/modules/desktops/desktops.h b/modules/desktops/desktops.h
new file mode 100644
index 0000000..05218d7
--- /dev/null
+++ b/modules/desktops/desktops.h
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#ifndef WIDGETS_DESKTOPS_H
+#define WIDGETS_DESKTOPS_H
+
+#include <Elementary.h>
+#include <glib.h>
+
+typedef struct Widgets_Desktops Widgets_Desktops;
+
+Widgets_Desktops *widgets_desktops_new(Evas_Object *bounds, GKeyFile *settings,
+ Eina_Bool (*save)(void *data), void *data);
+void widgets_desktops_free(Widgets_Desktops *desktops);
+void widgets_desktops_theme_set(Widgets_Desktops *desktops, const char *file);
+void widgets_desktops_controls_add(Widgets_Desktops *desktops, Evas_Object *box);
+
+#endif
diff --git a/modules/meson.build b/modules/meson.build
index 173cea4..4542c82 100644
--- a/modules/meson.build
+++ b/modules/meson.build
@@ -5,6 +5,7 @@ gadget_sources = files(
'clock/clock.c',
'clock/face.c',
'daylight/daylight.c',
+ 'desktops/desktops.c',
'logger/logger.c',
'music/artwork.c',
'music/music.c',
@@ -23,6 +24,6 @@ gadget_sources = files(
)
gadget_includes = include_directories(
- '.', 'clock', 'daylight', 'logger', 'music', 'notes',
+ '.', 'clock', 'daylight', 'desktops', 'logger', 'music', 'notes',
'sports', 'sysinfo', 'updates', 'weather',
)
diff --git a/modules/widgets_gadgets.c b/modules/widgets_gadgets.c
index 8e729fb..93f666b 100644
--- a/modules/widgets_gadgets.c
+++ b/modules/widgets_gadgets.c
@@ -21,6 +21,7 @@ widgets_gadgets_add(Widgets *state, Eina_Bool (*save)(void *))
config = state->config;
state->clock = widgets_clock_new(window, bounds, config, save, state);
state->daylight = widgets_daylight_new(window, bounds, config, save, state);
+ state->desktops = widgets_desktops_new(bounds, config, save, state);
state->logger = widgets_logger_new(window, bounds, config, save, state);
state->music = widgets_music_new(window, bounds, config, save, state);
state->notes = widgets_notes_new(window, bounds, config, save, state);
@@ -41,6 +42,7 @@ widgets_gadgets_theme_set(Widgets *state, unsigned int accent, unsigned int ink)
file = state->theme_path;
widgets_clock_theme_set(state->clock, NULL, file);
widgets_daylight_theme_set(state->daylight, file);
+ widgets_desktops_theme_set(state->desktops, file);
widgets_logger_theme_set(state->logger, file);
widgets_music_theme_set(state->music, file, EINA_TRUE, accent);
widgets_notes_theme_set(state->notes, file);
@@ -60,6 +62,7 @@ widgets_gadgets_free(Widgets *state)
widgets_notes_free(state->notes);
widgets_music_free(state->music);
widgets_logger_free(state->logger);
+ widgets_desktops_free(state->desktops);
widgets_daylight_free(state->daylight);
widgets_clock_free(state->clock);
}
diff --git a/widgets_private.h b/widgets_private.h
index 6e1d005..b444638 100644
--- a/widgets_private.h
+++ b/widgets_private.h
@@ -10,6 +10,7 @@ typedef struct _E_Client_Hook E_Client_Hook;
#include "clock.h"
#include "daylight.h"
+#include "desktops.h"
#include "logger.h"
#include "music.h"
#include "notes.h"
@@ -43,6 +44,7 @@ typedef struct
Widgets_Clock_Gadget *clock;
Widgets_Daylight *daylight;
+ Widgets_Desktops *desktops;
Widgets_Logger *logger;
Widgets_Music *music;
Widgets_Notes *notes;
diff --git a/widgets_settings.c b/widgets_settings.c
index 00352f0..c712176 100644
--- a/widgets_settings.c
+++ b/widgets_settings.c
@@ -141,6 +141,7 @@ widgets_settings_open(Widgets *state)
widgets_clock_controls_add(state->clock, controls);
widgets_daylight_controls_add(state->daylight, controls);
+ widgets_desktops_controls_add(state->desktops, controls);
widgets_logger_controls_add(state->logger, controls);
widgets_music_controls_add(state->music, controls);
widgets_notes_controls_add(state->notes, controls, widgets_settings_close, state);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.