Propagate Layer changes via Style command on-the-fly.
[fvwm.git] / fvwm / execcontext.c
blobda7c23087b054e6022784d8944a919ed30e66399
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.
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.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 /* ---------------------------- included header files ---------------------- */
19 #define FEVENT_PRIVILEGED_ACCESS
20 #include "config.h"
21 #undef FEVENT_PRIVILEGED_ACCESS
22 #include <stdio.h>
24 #include "fvwm.h"
25 #include "externs.h"
26 #include "execcontext.h"
28 /* ---------------------------- local definitions -------------------------- */
30 /* ---------------------------- local macros ------------------------------- */
32 /* ---------------------------- imports ------------------------------------ */
34 /* ---------------------------- included code files ------------------------ */
36 /* ---------------------------- local types -------------------------------- */
38 /* ---------------------------- forward declarations ----------------------- */
40 /* ---------------------------- local variables ---------------------------- */
42 #undef DEBUG_EXECCONTEXT
43 #ifdef DEBUG_EXECCONTEXT
44 static exec_context_t *x[256];
45 static int nx = 0;
46 #endif
48 /* ---------------------------- exported variables (globals) --------------- */
50 /* ---------------------------- local functions ---------------------------- */
52 static void __exc_change_context(
53 exec_context_t *exc, exec_context_changes_t *ecc,
54 exec_context_change_mask_t mask)
56 if (mask & ECC_TYPE)
58 exc->type = ecc->type;
60 if (mask & ECC_ETRIGGER)
62 if (ecc->x.etrigger == NULL)
64 fev_copy_last_event(&exc->private_data.te);
66 else
68 exc->private_data.te = *ecc->x.etrigger;
70 exc->x.etrigger = &(exc->private_data.te);
72 if (mask & ECC_FW)
74 exc->w.fw = ecc->w.fw;
76 if (mask & ECC_W)
78 exc->w.w = ecc->w.w;
80 if (mask & ECC_WCONTEXT)
82 exc->w.wcontext = ecc->w.wcontext;
84 if (mask & ECC_MODULE)
86 exc->m.module = ecc->m.module;
89 return;
92 /* ---------------------------- interface functions ------------------------ */
94 const exec_context_t *exc_create_null_context(void)
96 exec_context_t *exc;
97 #ifdef DEBUG_EXECCONTEXT
98 int i;
99 #endif
101 exc = (exec_context_t *)safecalloc(1, sizeof(exec_context_t));
102 #ifdef DEBUG_EXECCONTEXT
103 fprintf(stderr, "xxx+0 ");
104 for(i=0;i<nx;i++)fprintf(stderr," ");
105 x[nx]=exc;nx++;
106 fprintf(stderr, "0x%08x\n", (int)exc);
107 #endif
108 exc->type = EXCT_NULL;
109 fev_make_null_event(&exc->private_data.te, dpy);
110 exc->x.etrigger = &exc->private_data.te;
111 exc->x.elast = fev_get_last_event_address();
112 exc->m.module = NULL;
114 return exc;
117 const exec_context_t *exc_create_context(
118 exec_context_changes_t *ecc, exec_context_change_mask_t mask)
120 exec_context_t *exc;
122 #ifdef DEBUG_EXECCONTEXT
123 if (!(mask & ECC_TYPE)) abort();
124 #endif
125 exc = (exec_context_t *)exc_create_null_context();
126 __exc_change_context(exc, ecc, mask);
128 return exc;
131 const exec_context_t *exc_clone_context(
132 const exec_context_t *excin, exec_context_changes_t *ecc,
133 exec_context_change_mask_t mask)
135 exec_context_t *exc;
136 #ifdef DEBUG_EXECCONTEXT
137 int i;
138 #endif
140 exc = (exec_context_t *)safemalloc(sizeof(exec_context_t));
141 #ifdef DEBUG_EXECCONTEXT
142 fprintf(stderr, "xxx+= ");
143 for(i=0;i<nx;i++)fprintf(stderr," ");
144 x[nx]=exc;nx++;
145 fprintf(stderr, "0x%08x\n", (int)exc);
146 #endif
147 memcpy(exc, excin, sizeof(*exc));
148 __exc_change_context(exc, ecc, mask);
150 return exc;
153 void exc_destroy_context(
154 const exec_context_t *exc)
156 #ifdef DEBUG_EXECCONTEXT
157 int i;
158 if (nx == 0||x[nx-1] != exc)abort();
159 nx--;
160 fprintf(stderr, "xxx-- ");
161 for(i=0;i<nx;i++)fprintf(stderr," ");
162 fprintf(stderr, "0x%08x\n", (int)exc);
163 #endif
164 free((exec_context_t *)exc);
166 return;