1 /* -*-c-*- */
2 /* This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, see: <http://www.gnu.org/licenses/>
14  */
15 
16 /* ---------------------------- included header files ---------------------- */
17 
18 #define FEVENT_PRIVILEGED_ACCESS
19 #include "config.h"
20 #include <stdio.h>
21 
22 #include "fvwm.h"
23 #include "externs.h"
24 #include "execcontext.h"
25 #include "libs/FEvent.h"
26 
27 #undef PEVENT_PRIVILEGED_ACCESS
28 
29 /* ---------------------------- local definitions -------------------------- */
30 
31 /* ---------------------------- local macros ------------------------------- */
32 
33 /* ---------------------------- imports ------------------------------------ */
34 
35 /* ---------------------------- included code files ------------------------ */
36 
37 /* ---------------------------- local types -------------------------------- */
38 
39 /* ---------------------------- forward declarations ----------------------- */
40 
41 /* ---------------------------- local variables ---------------------------- */
42 
43 #undef DEBUG_EXECCONTEXT
44 #ifdef DEBUG_EXECCONTEXT
45 static exec_context_t *x[256];
46 static int nx = 0;
47 #endif
48 
49 /* ---------------------------- exported variables (globals) --------------- */
50 
51 /* ---------------------------- local functions ---------------------------- */
52 
__exc_change_context(exec_context_t * exc,exec_context_changes_t * ecc,exec_context_change_mask_t mask)53 static void __exc_change_context(
54 	exec_context_t *exc, exec_context_changes_t *ecc,
55 	exec_context_change_mask_t mask)
56 {
57 	if (mask & ECC_TYPE)
58 	{
59 		exc->type = ecc->type;
60 	}
61 	if (mask & ECC_ETRIGGER)
62 	{
63 		if (ecc->x.etrigger == NULL)
64 		{
65 			fev_copy_last_event(&exc->private_data.te);
66 		}
67 		else
68 		{
69 			exc->private_data.te = *ecc->x.etrigger;
70 		}
71 		exc->x.etrigger = &(exc->private_data.te);
72 	}
73 	if (mask & ECC_FW)
74 	{
75 		exc->w.fw = ecc->w.fw;
76 	}
77 	if (mask & ECC_W)
78 	{
79 		exc->w.w = ecc->w.w;
80 	}
81 	if (mask & ECC_WCONTEXT)
82 	{
83 		exc->w.wcontext = ecc->w.wcontext;
84 	}
85 	if (mask & ECC_MODULE)
86 	{
87 		exc->m.module = ecc->m.module;
88 	}
89 
90 	return;
91 }
92 
93 /* ---------------------------- interface functions ------------------------ */
94 
exc_create_null_context(void)95 const exec_context_t *exc_create_null_context(void)
96 {
97 	exec_context_t *exc;
98 #ifdef DEBUG_EXECCONTEXT
99 	int i;
100 #endif
101 
102 	exc = fxcalloc(1, sizeof(exec_context_t));
103 #ifdef DEBUG_EXECCONTEXT
104 fvwm_debug(__func__, "xxx+0 ");
105 for(i=0;i<nx;i++) fvwm_debug(__func__, "  ");
106 x[nx]=exc;nx++;
107 fvwm_debug(__func__, "0x%08x\n", (int)exc);
108 #endif
109 	exc->type = EXCT_NULL;
110 	fev_make_null_event(&exc->private_data.te, dpy);
111 	exc->x.etrigger = &exc->private_data.te;
112 	exc->x.elast = fev_get_last_event_address();
113 	exc->m.module = NULL;
114 
115 	return exc;
116 }
117 
exc_create_context(exec_context_changes_t * ecc,exec_context_change_mask_t mask)118 const exec_context_t *exc_create_context(
119 	exec_context_changes_t *ecc, exec_context_change_mask_t mask)
120 {
121 	exec_context_t *exc;
122 
123 #ifdef DEBUG_EXECCONTEXT
124 if (!(mask & ECC_TYPE)) abort();
125 #endif
126 	exc = (exec_context_t *)exc_create_null_context();
127 	__exc_change_context(exc, ecc, mask);
128 
129 	return exc;
130 }
131 
exc_clone_context(const exec_context_t * excin,exec_context_changes_t * ecc,exec_context_change_mask_t mask)132 const exec_context_t *exc_clone_context(
133 	const exec_context_t *excin, exec_context_changes_t *ecc,
134 	exec_context_change_mask_t mask)
135 {
136 	exec_context_t *exc;
137 #ifdef DEBUG_EXECCONTEXT
138 int i;
139 #endif
140 
141 	exc = fxmalloc(sizeof(exec_context_t));
142 #ifdef DEBUG_EXECCONTEXT
143 fvwm_debug(__func__, "xxx+= ");
144 for(i=0;i<nx;i++) fvwm_debug(__func__, "  ");
145 x[nx]=exc;nx++;
146 fvwm_debug(__func__, "0x%08x\n", (int)exc);
147 #endif
148 	memcpy(exc, excin, sizeof(*exc));
149 	__exc_change_context(exc, ecc, mask);
150 
151 	return exc;
152 }
153 
exc_destroy_context(const exec_context_t * exc)154 void exc_destroy_context(
155 	const exec_context_t *exc)
156 {
157 #ifdef DEBUG_EXECCONTEXT
158 int i;
159 if (nx == 0||x[nx-1] != exc)abort();
160 nx--;
161 fvwm_debug(__func__, "xxx-- ");
162 for(i=0;i<nx;i++) fvwm_debug(__func__, "  ");
163 fvwm_debug(__func__, "0x%08x\n", (int)exc);
164 #endif
165 	free((exec_context_t *)exc);
166 
167 	return;
168 }
169