summaryrefslogtreecommitdiff
path: root/HACKING-PLUGINS.md
blob: 5150074e73f5e05d867c01c96b6f0aff7ae729fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# EOM Plugin Development Guide

Quick guide for creating plugins for Eye of MATE (EOM).

## Quick Start

EOM uses **libpeas** for plugins. A plugin extends EOM by implementing the `EomWindowActivatable` interface.

**What you can do:**
- Add menu items and toolbar buttons
- React to image changes
- Access image data and metadata
- Add custom UI widgets

**Languages:** C or Python 3

**Install location:** `~/.local/share/eom/plugins/your-plugin-name/`

## Plugin Structure

Every plugin needs these files:

1. **Plugin header** - `my-plugin.h`
2. **Plugin code** - `my-plugin.c`
3. **Plugin descriptor** - `my-plugin.plugin`
4. **Build file** - `Makefile`

### Basic Plugin Template

**Note:** This is a simplified template. For a complete working example with all necessary boilerplate, see `plugins/reload/` in the EOM source tree.

```c
// my-plugin.h
#ifndef __MY_PLUGIN_H__
#define __MY_PLUGIN_H__

#include <glib-object.h>
#include <libpeas/peas-extension-base.h>
#include <libpeas/peas-object-module.h>
#include <eom-window.h>

G_BEGIN_DECLS

#define MY_TYPE_PLUGIN (my_plugin_get_type ())
G_DECLARE_FINAL_TYPE (MyPlugin, my_plugin, MY, PLUGIN, PeasExtensionBase)

struct _MyPlugin {
    PeasExtensionBase parent;
    EomWindow *window;
    GtkActionGroup *action_group;
    guint ui_id;
};

GType my_plugin_get_type (void) G_GNUC_CONST;
G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);

G_END_DECLS

#endif /* __MY_PLUGIN_H__ */
```

```c
// my-plugin.c
#include "my-plugin.h"
#include <eom-window-activatable.h>

static void eom_window_activatable_iface_init (EomWindowActivatableInterface *iface);

// Register the plugin type
G_DEFINE_DYNAMIC_TYPE_EXTENDED (MyPlugin, my_plugin,
    PEAS_TYPE_EXTENSION_BASE, 0,
    G_IMPLEMENT_INTERFACE_DYNAMIC (EOM_TYPE_WINDOW_ACTIVATABLE,
                                   eom_window_activatable_iface_init))

enum {
    PROP_0,
    PROP_WINDOW
};

// Initialize plugin instance
static void
my_plugin_init (MyPlugin *plugin)
{
    // Initialize your plugin data here
}

// Clean up plugin resources
static void
my_plugin_dispose (GObject *object)
{
    MyPlugin *plugin = MY_PLUGIN (object);

    if (plugin->window != NULL) {
        g_object_unref (plugin->window);
        plugin->window = NULL;
    }

    G_OBJECT_CLASS (my_plugin_parent_class)->dispose (object);
}

// Set plugin properties
static void
my_plugin_set_property (GObject      *object,
                        guint         prop_id,
                        const GValue *value,
                        GParamSpec   *pspec)
{
    MyPlugin *plugin = MY_PLUGIN (object);

    switch (prop_id) {
    case PROP_WINDOW:
        plugin->window = EOM_WINDOW (g_value_dup_object (value));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}

// Get plugin properties
static void
my_plugin_get_property (GObject    *object,
                        guint       prop_id,
                        GValue     *value,
                        GParamSpec *pspec)
{
    MyPlugin *plugin = MY_PLUGIN (object);

    switch (prop_id) {
    case PROP_WINDOW:
        g_value_set_object (value, plugin->window);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}

// Called when plugin is enabled
static void
my_plugin_activate (EomWindowActivatable *activatable)
{
    MyPlugin *plugin = MY_PLUGIN (activatable);

    // Add menu items, connect signals, etc.
}

// Called when plugin is disabled
static void
my_plugin_deactivate (EomWindowActivatable *activatable)
{
    MyPlugin *plugin = MY_PLUGIN (activatable);

    // Remove menu items, disconnect signals, etc.
}

// Initialize plugin class
static void
my_plugin_class_init (MyPluginClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);

    object_class->dispose = my_plugin_dispose;
    object_class->set_property = my_plugin_set_property;
    object_class->get_property = my_plugin_get_property;

    g_object_class_override_property (object_class, PROP_WINDOW, "window");
}

// Required by G_DEFINE_DYNAMIC_TYPE_EXTENDED
static void
my_plugin_class_finalize (MyPluginClass *klass)
{
    // Dummy function for dynamic type registration
}

// Implement the activatable interface
static void
eom_window_activatable_iface_init (EomWindowActivatableInterface *iface)
{
    iface->activate = my_plugin_activate;
    iface->deactivate = my_plugin_deactivate;
}

// Register with libpeas
G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
    my_plugin_register_type (G_TYPE_MODULE (module));
    peas_object_module_register_extension_type (module,
        EOM_TYPE_WINDOW_ACTIVATABLE, MY_TYPE_PLUGIN);
}
```

### Plugin Descriptor

```ini
# my-plugin.plugin
[Plugin]
Module=my-plugin
IAge=2
Name=My Plugin Name
Description=What this plugin does
Authors=Your Name <email@example.com>
Copyright=Copyright © 2025 Your Name
Website=https://mate-desktop.org
```

### Build File

```makefile
# Makefile
PLUGIN_NAME = my-plugin
SOURCES = my-plugin.c
HEADERS = my-plugin.h

USER_DIR = $(HOME)/.local/share/eom/plugins/$(PLUGIN_NAME)
CFLAGS = `pkg-config --cflags gtk+-3.0 eom libpeas-1.0` -fPIC
LDFLAGS = `pkg-config --libs gtk+-3.0 eom libpeas-1.0` -shared

all: lib$(PLUGIN_NAME).so

lib$(PLUGIN_NAME).so: $(SOURCES) $(HEADERS)
	$(CC) $(CFLAGS) $(SOURCES) -o $@ $(LDFLAGS)

install: all
	mkdir -p $(USER_DIR)
	cp lib$(PLUGIN_NAME).so $(USER_DIR)/
	cp $(PLUGIN_NAME).plugin $(USER_DIR)/

clean:
	rm -f lib$(PLUGIN_NAME).so
```

## Common Tasks

### Adding a Menu Item

```c
static void
my_action_callback (GtkAction *action, EomWindow *window)
{
    // Do something when menu item is clicked
}

static const GtkActionEntry actions[] = {
    { "MyAction", NULL, "Menu Label", "<Ctrl>M",
      "Tooltip text", G_CALLBACK (my_action_callback) }
};

static const gchar* ui_xml =
    "<ui><menubar name='MainMenu'>"
    "<menu name='ToolsMenu' action='Tools'>"
    "<menuitem action='MyAction'/>"
    "</menu></menubar></ui>";

static void
my_plugin_activate (EomWindowActivatable *activatable)
{
    MyPlugin *plugin = MY_PLUGIN (activatable);
    GtkUIManager *manager = eom_window_get_ui_manager (plugin->window);

    plugin->action_group = gtk_action_group_new ("MyActions");
    gtk_action_group_add_actions (plugin->action_group, actions,
                                  G_N_ELEMENTS (actions), plugin->window);
    gtk_ui_manager_insert_action_group (manager, plugin->action_group, -1);
    plugin->ui_id = gtk_ui_manager_add_ui_from_string (manager, ui_xml, -1, NULL);
}
```

### Working with Images

```c
// Get current image
EomImage *image = eom_window_get_image (window);

// Get image data
GdkPixbuf *pixbuf = eom_image_get_pixbuf (image);
gint width, height;
eom_image_get_size (image, &width, &height);

// Check image type
if (eom_image_is_jpeg (image)) { /* ... */ }

// Transform image
EomTransform *transform = eom_transform_rotate_new (90);
eom_image_transform (image, transform, NULL);
g_object_unref (transform);

// Mark as modified
eom_image_modified (image);
```

### Responding to Events

```c
static void
on_image_changed (EomThumbView *view, MyPlugin *plugin)
{
    EomImage *image = eom_window_get_image (plugin->window);
    // React to image change
}

static void
my_plugin_activate (EomWindowActivatable *activatable)
{
    MyPlugin *plugin = MY_PLUGIN (activatable);
    GtkWidget *thumbview = eom_window_get_thumb_view (plugin->window);

    plugin->signal_id = g_signal_connect (thumbview, "selection_changed",
                                          G_CALLBACK (on_image_changed), plugin);
}

static void
my_plugin_deactivate (EomWindowActivatable *activatable)
{
    MyPlugin *plugin = MY_PLUGIN (activatable);
    GtkWidget *thumbview = eom_window_get_thumb_view (plugin->window);

    g_signal_handler_disconnect (thumbview, plugin->signal_id);
}
```

## Key APIs

### EomWindow

```c
EomImage *     eom_window_get_image      (EomWindow *window);
GtkUIManager * eom_window_get_ui_manager (EomWindow *window);
GtkWidget *    eom_window_get_view       (EomWindow *window);
GtkWidget *    eom_window_get_sidebar    (EomWindow *window);
GtkWidget *    eom_window_get_statusbar  (EomWindow *window);
void           eom_window_reload_image   (EomWindow *window);
```

### EomImage

```c
GdkPixbuf * eom_image_get_pixbuf  (EomImage *img);
void        eom_image_get_size    (EomImage *img, gint *width, gint *height);
void        eom_image_transform   (EomImage *img, EomTransform *trans, EomJob *job);
void        eom_image_modified    (EomImage *img);
gboolean    eom_image_is_jpeg     (EomImage *img);
```

See `src/eom-window.h` and `src/eom-image.h` for complete API.

## Building and Testing

```bash
# Build the plugin
make

# Install to user directory
make install

# Test
eom
# Go to Edit → Preferences → Plugins
# Enable your plugin
```

## Built-in Examples

Study these plugins in the `plugins/` directory:

1. **fullscreen** - Simple event handling (double-click to toggle fullscreen)
2. **reload** - Adding menu items (reload image from disk)
3. **statusbar-date** - Widget manipulation and EXIF reading

## Tips

- **Memory management**: Always `g_object_unref()` objects and `g_free()` allocated memory
- **Cleanup**: Remove all UI elements and disconnect all signals in `deactivate()`
- **Debugging**: Run with `EOM_DEBUG_PLUGINS=1 eom` or `EOM_DEBUG=1 eom` to see plugin messages
- **Headers**: All EOM headers are in `/usr/include/eom/` (install `libeom-dev`)

## Complete Example

See `plugins/reload/` in the EOM source for a complete, simple example showing:
- Plugin structure with proper GObject boilerplate
- Adding a menu item with keyboard shortcut
- Calling EOM window functions
- Proper activation and deactivation

## Resources

- **libpeas source/examples**: https://gitlab.gnome.org/GNOME/libpeas/-/tree/1.36?ref_type=heads
- **EOM headers**: `/usr/include/eom/` or `src/` in source tree (install `libeom-dev`)
- **GTK+ 3 docs**: https://docs.gtk.org/gtk3/
- **MATE wiki**: https://wiki.mate-desktop.org/
- **GObject Tutorial**: https://docs.gtk.org/gobject/

## Next Steps

1. Copy one of the built-in plugins as a template
2. Modify it for your needs
3. Build and test iteratively
4. Share your plugin with the community!

For advanced topics (GSettings integration, complex UI, Python plugins), refer to the built-in plugin code and GTK+/libpeas documentation.