summaryrefslogtreecommitdiff
path: root/plugins/fullscreen/eom-fullscreen-plugin.c
blob: dd31d829d44c89676ff09b227482193ce130b174 (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
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "eom-fullscreen-plugin.h"

#include <gmodule.h>
#include <glib/gi18n-lib.h>

#include <eom-debug.h>
#include <eom-scroll-view.h>

#define WINDOW_DATA_KEY "EomFullscreenWindowData"

EOM_PLUGIN_REGISTER_TYPE (EomFullscreenPlugin, eom_fullscreen_plugin)

typedef struct {
	gulong signal_id;
} WindowData;

static gboolean
on_button_press (GtkWidget      *button,
                 GdkEventButton *event,
                 EomWindow      *window)
{
	if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
	{
		EomWindowMode mode = eom_window_get_mode (window);

		if (mode == EOM_WINDOW_MODE_SLIDESHOW || mode == EOM_WINDOW_MODE_FULLSCREEN)
		{
			eom_window_set_mode (window, EOM_WINDOW_MODE_NORMAL);
		}
		else if (mode == EOM_WINDOW_MODE_NORMAL)
		{
			eom_window_set_mode (window, EOM_WINDOW_MODE_FULLSCREEN);
		}

		return TRUE;
	}

	return FALSE;
}

static void
free_window_data (WindowData *data)
{
	g_return_if_fail (data != NULL);

	eom_debug (DEBUG_PLUGINS);

	g_free (data);
}

static void
eom_fullscreen_plugin_init (EomFullscreenPlugin *plugin)
{
	eom_debug_message (DEBUG_PLUGINS, "EomFullscreenPlugin initializing");
}

static void
eom_fullscreen_plugin_finalize (GObject *object)
{
	eom_debug_message (DEBUG_PLUGINS, "EomFullscreenPlugin finalizing");

	G_OBJECT_CLASS (eom_fullscreen_plugin_parent_class)->finalize (object);
}

static void
impl_activate (EomPlugin *plugin,
               EomWindow *window)
{
	GtkWidget *view = eom_window_get_view (window);
	WindowData *data;

	eom_debug (DEBUG_PLUGINS);

	data = g_new (WindowData, 1);

	data->signal_id = g_signal_connect (G_OBJECT (view), "button-press-event",
	                                    G_CALLBACK (on_button_press), window);

	g_object_set_data_full (G_OBJECT(window), WINDOW_DATA_KEY, data, (GDestroyNotify) free_window_data);
}

static void
impl_deactivate (EomPlugin *plugin, EomWindow *window)
{
	GtkWidget *view = eom_window_get_view (window);
	WindowData *data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY);

	g_signal_handler_disconnect (view, data->signal_id);

	g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
}

static void
impl_update_ui (EomPlugin *plugin,
                EomWindow *window)
{
	/* Nothing */
}

static void
eom_fullscreen_plugin_class_init (EomFullscreenPluginClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
	EomPluginClass *plugin_class = EOM_PLUGIN_CLASS (klass);

	object_class->finalize = eom_fullscreen_plugin_finalize;

	plugin_class->activate = impl_activate;
	plugin_class->deactivate = impl_deactivate;
	plugin_class->update_ui = impl_update_ui;
}