]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/dope/lib/dope/common/main.c
94387fb50e1b09d1545c75d16106a0e8a19d5a07
[l4.git] / l4 / pkg / dope / lib / dope / common / main.c
1 /*
2  * \brief   DOpE client library
3  * \date    2002-11-13
4  * \author  Norman Feske <nf2@inf.tu-dresden.de>
5  */
6
7 /*
8  * Copyright (C) 2002-2003  Norman Feske  <nf2@os.inf.tu-dresden.de>
9  * Technische Universitaet Dresden, Operating Systems Research Group
10  *
11  * This file is part of the DOpE package, which is distributed under
12  * the  terms  of the  GNU General Public Licence 2.  Please see the
13  * COPYING file for details.
14  */
15
16 /*** GENERIC INCLUDES ***/
17 #include <l4/re/c/event.h>
18 #include <l4/input/libinput.h>
19 #include <stdio.h>
20 #include <stdarg.h>
21
22 #include <dopelib.h>
23 #include "dopestd.h"
24 #include "sync.h"
25 #include "init.h"
26 #include "misc.h"
27
28 #define EVENT_PRESS         1
29 #define EVENT_RELEASE       2
30 #define EVENT_MOTION        3
31 #define EVENT_MOUSE_ENTER   4
32 #define EVENT_MOUSE_LEAVE   5
33 #define EVENT_KEY_REPEAT    6
34 #define EVENT_ABSMOTION     7
35 #define EVENT_ACTION       99
36
37
38 struct cb_data
39 {
40   void (*callback)(dope_event *,void *);
41   void *arg;
42 };
43
44 /*** UTILITY: CONVERT CALLBACK FUNCTION TO BIND ARGUMENT STRING ***/
45 char *dopelib_callback_to_bindarg(void (*callback)(dope_event *,void *),
46                                   void *arg,
47                                   char *dst_buf, int dst_len)
48 {
49   struct cb_data *c = malloc(sizeof(struct cb_data));
50   c->callback = callback;
51   c->arg = arg;
52   snprintf(dst_buf, dst_len, "0x%lx", (unsigned long)c);
53   return dst_buf;
54 }
55
56
57 /*** INTERFACE: BIND AN EVENT TO A DOpE WIDGET ***/
58 void dope_bind(const char *var, const char *event_type,
59                void (*callback)(dope_event *,void *), void *arg)
60 {
61   char cmdbuf[256];
62   char bindbuf[64];
63
64   dopelib_mutex_lock(dopelib_cmdf_mutex);
65
66   dopelib_callback_to_bindarg(callback, arg, bindbuf, sizeof(bindbuf));
67   snprintf(cmdbuf, sizeof(cmdbuf), "%s.bind(\"%s\",%s)",
68       var, event_type, bindbuf);
69
70   dope_cmd(cmdbuf);
71   dopelib_mutex_unlock(dopelib_cmdf_mutex);
72 }
73
74
75 /*** INTERFACE: BIND AN EVENT TO A DOpE WIDGET SPECIFIED AS FORMAT STRING ***/
76 void dope_bindf(const char *varfmt, const char *event_type,
77                 void (*callback)(dope_event *,void *), void *arg,...)
78 {
79   char varstr[512];
80   va_list list;
81
82   /* decode varargs */
83   va_start(list, arg);
84   vsnprintf(varstr, sizeof(varstr), varfmt, list);
85   va_end(list);
86
87   dope_bind(varstr, event_type, callback, arg);
88 }
89
90 char *dope_get_bindarg(l4re_event_t *ev)
91 {
92   if (!ev->stream_id)
93     return NULL;
94
95   struct cb_data *cb = (struct cb_data*)(ev->stream_id);
96   if (!cb->callback)
97     return NULL;
98
99   return cb->arg;
100 }
101
102 void dope_process_event(l4re_event_t *ev);
103
104 /*** INTERFACE: PROCESS SINGLE DOpE EVENT ***/
105 void dope_process_event(l4re_event_t *ev)
106 {
107   if (!ev->stream_id)
108     return;
109
110   struct cb_data *cb = (struct cb_data*)(ev->stream_id);
111   if (!cb->callback)
112     return;
113
114   cb->callback(ev, cb->arg);
115 }
116
117 void dope_deinit_app(void) {}
118
119
120 /*** INTERFACE: DISCONNECT FROM DOpE ***
121  *
122  * FIXME: wait for the finishing of the current command and block net commands
123  */
124 void dope_deinit(void) {}
125