proto asynccallback works
[mozilla_edje_plugin.git] / src / plugin.c
blob5557926cd6c154f891b3a23541392e630e4a5608
1 #include "plugin.h"
3 /*
4 * Implementations of plugin API functions
5 */
7 /*
8 * TODO
9 * change to iterative call, so we need no trigger in a seperate thread
10 * and hence no thread safety measures.
12 void
13 mep_asynccall (void *data)
15 PluginInstance *pi = (PluginInstance *) data;
16 ecore_main_loop_iterate ();
19 int
20 mep_animator (void *data)
22 PluginInstance *pi = (PluginInstance *) data;
23 evas_render (pi->evas);
24 return 1;
28 * this is a bloody hack to enable ecore_main_loop_iterate
29 * ecore_main_loop_iterate does not run in a seperate thread
30 * we therefore send a signal via the X server to the event handle
31 * loop and call ecore_main_loop_iterate from the thread it
32 * was initiated. this works. the method with NPP_PluginAsyncCall
33 * would be ways more elegant, but does not yet work
35 void *
36 mep_trigger (void *data)
38 PluginInstance *pi = (PluginInstance *) data;
39 while (!pi->done)
41 usleep (10000); // maximal FPS=100
42 NPN_PluginThreadAsyncCall (pi->instance, mep_asynccall, NULL);
45 NPRect rect;
46 rect.top = 0;
47 rect.left = 0;
48 rect.bottom = 400;
49 rect.right = 400;
50 NPN_InvalidateRect (pi->instance, &rect);
52 NPN_ForceRedraw (pi->instance);
53 XSendEvent (pi->display, pi->window, 1, NoEventMask, (XEvent *) &(pi->msg));
57 return NULL;
60 void
61 mep_event_handler (Widget xtwidget, void *data, XEvent *xevent, Boolean *b)
63 PluginInstance *pi = (PluginInstance *) data;
64 Evas *evas = pi->evas;
65 XEvent ev = *xevent;
67 //printf ("event type: %d\n", ev.type);
69 if (ev.type > 0)
70 switch (ev.type) {
71 case ButtonPress:
72 evas_event_feed_mouse_move(evas, ev.xbutton.x, ev.xbutton.y, 0, NULL);
73 evas_event_feed_mouse_down(evas, ev.xbutton.button, EVAS_BUTTON_NONE, 0, NULL);
74 break;
75 case ButtonRelease:
76 evas_event_feed_mouse_move(evas, ev.xbutton.x, ev.xbutton.y, 0, NULL);
77 evas_event_feed_mouse_up(evas, ev.xbutton.button, EVAS_BUTTON_NONE, 0, NULL);
78 break;
79 case MotionNotify:
80 evas_event_feed_mouse_move(evas, ev.xmotion.x, ev.xmotion.y, 0, NULL);
81 break;
82 case Expose:
83 evas_damage_rectangle_add(evas,
84 ev.xexpose.x,
85 ev.xexpose.y,
86 ev.xexpose.width,
87 ev.xexpose.height);
88 break;
89 case ConfigureNotify:
90 evas_output_size_set(evas,
91 ev.xconfigure.width,
92 ev.xconfigure.height);
93 break;
94 case EnterNotify:
95 evas_object_focus_set (pi->edj, 1);
96 //trigger (pi);
97 break;
98 case LeaveNotify:
99 evas_object_focus_set (pi->edj, 0);
100 //trigger (pi);
101 break;
102 case ClientMessage: // 33
103 if (ev.xclient.message_type == pi->atom)
104 ecore_main_loop_iterate ();
105 break;
106 default:
107 break;
112 void
113 mep_cb_ui_play (void *data, Evas_Object *edj, const char *emission, const char *source)
115 PluginInstance *pi = (PluginInstance *) data;
116 if (!edje_object_play_get (pi->edj)) // if paused
118 edje_object_play_set (pi->edj, 1);
119 //edje_object_animation_set (pi->edj, 1);
123 void
124 mep_cb_ui_pause (void *data, Evas_Object *edj, const char *emission, const char *source)
126 PluginInstance *pi = (PluginInstance *) data;
127 if (edje_object_play_get (pi->edj)) // if playing
129 edje_object_play_set (pi->edj, 0);
130 //edje_object_animation_set (pi->edj, 0);
134 void
135 mep_cb_ui_save (void *data, Evas_Object *edj, const char *emission, const char *source)
137 PluginInstance *pi = (PluginInstance *) data;
138 // TODO
141 void
142 mep_cb_ui_config (void *data, Evas_Object *edj, const char *emission, const char *source)
144 PluginInstance *pi = (PluginInstance *) data;
145 // TODO
148 void
149 mep_configure (PluginInstance *pi)
151 char config_path[256];
152 sprintf (config_path, "%s/%s", CONFIGDIR, "config.edb");
153 ecore_config_file_load (config_path);
154 pi->config_theme = strdup (ecore_config_theme_get ("theme"));
155 pi->config_engine = strdup (ecore_config_string_get ("engine"));
156 pi->config_fps = ecore_config_int_get ("fps");