2
* Misc function implementation
4
* These are things that either don't fit neatly into another category,
5
* or fit into a category too small to be worth making individual files
14
#include "functions.h"
15
#include "functions_defs.h"
16
#include "functions_internal.h"
25
#include "win_iconify.h"
26
#include "windowbox.h"
27
#include "workspace_utils.h"
29
#include "ext/repl_str.h"
36
DFHANDLER(startanimation)
41
DFHANDLER(stopanimation)
46
DFHANDLER(speedupanimation)
48
ModifyAnimationSpeed(1);
51
DFHANDLER(slowdownanimation)
53
ModifyAnimationSpeed(-1);
63
if(action && ! strncmp(action, "WGOTO : ", 8)) {
64
GotoWorkSpaceByName(/* XXXXX */ Scr->currentvs,
65
((char *)action) + 8);
71
while(item && item->sub) {
72
if(!item->sub->defaultitem) {
75
if(item->sub->defaultitem->func != F_MENU) {
78
item = item->sub->defaultitem;
80
if(item && item->sub && item->sub->defaultitem) {
81
ExecuteFunction(item->sub->defaultitem->func,
82
item->sub->defaultitem->action,
83
w, tmp_win, eventp, context, pulldown);
94
if(ActiveMenu->pinned) {
95
XUnmapWindow(dpy, ActiveMenu->w);
96
ActiveMenu->mapped = MRM_UNMAPPED;
99
XWindowAttributes attr;
102
if(ActiveMenu->pmenu == NULL) {
103
menu = malloc(sizeof(MenuRoot));
106
menu->mapped = MRM_NEVER;
109
menu->width -= 16 + 10;
112
ActiveMenu->pmenu = menu;
115
menu = ActiveMenu->pmenu;
117
if(menu->mapped == MRM_MAPPED) {
120
XGetWindowAttributes(dpy, ActiveMenu->w, &attr);
123
XMoveWindow(dpy, menu->w, menu->x, menu->y);
124
XMapRaised(dpy, menu->w);
125
menu->mapped = MRM_MAPPED;
133
* Alternate keymaps/contexts
142
stat_ = sscanf(action, "%d", &alt);
146
if((alt < 1) || (alt > 5)) {
149
AlternateKeymap = Alt1Mask << (alt - 1);
150
XGrabPointer(dpy, Scr->Root, True, ButtonPressMask | ButtonReleaseMask,
151
GrabModeAsync, GrabModeAsync,
152
Scr->Root, Scr->AlterCursor, CurrentTime);
153
func_reset_cursor = false; // Leave special cursor alone
154
XGrabKeyboard(dpy, Scr->Root, True, GrabModeAsync, GrabModeAsync, CurrentTime);
158
DFHANDLER(altcontext)
160
AlternateContext = true;
161
XGrabPointer(dpy, Scr->Root, False, ButtonPressMask | ButtonReleaseMask,
162
GrabModeAsync, GrabModeAsync,
163
Scr->Root, Scr->AlterCursor, CurrentTime);
164
func_reset_cursor = false; // Leave special cursor alone
165
XGrabKeyboard(dpy, Scr->Root, False, GrabModeAsync, GrabModeAsync, CurrentTime);
172
* A few trivial ctwm-control-ish meta-functions
181
DoRestart(eventp->xbutton.time);
197
* Special windowbox-related
199
DFHANDLER(fittocontent)
201
if(!tmp_win->iswinbox) {
205
fittocontent(tmp_win);
211
* A few things that are sorta windows/icons related, but don't really
212
* fit with the window-targetted things in functions_win.
214
DFHANDLER(showbackground)
216
ShowBackground(Scr->currentvs, -1);
219
DFHANDLER(raiseicons)
221
for(TwmWindow *t = Scr->FirstWindow; t != NULL; t = t->next) {
222
if(t->icon && t->icon->w) {
223
OtpRaise(t, IconWin);
228
DFHANDLER(rescuewindows)
236
* Despite the name, this is more like 'gotoworkspace' than the other
237
* 'warpto*' funcs, as it's just about switching your view, not anything
240
DFHANDLER(warptoscreen)
242
if(strcmp(action, WARPSCREEN_NEXT) == 0) {
243
WarpToScreen(Scr->screen + 1, 1);
245
else if(strcmp(action, WARPSCREEN_PREV) == 0) {
246
WarpToScreen(Scr->screen - 1, -1);
248
else if(strcmp(action, WARPSCREEN_BACK) == 0) {
249
WarpToScreen(PreviousScreen, 0);
252
WarpToScreen(atoi(action), 0);
263
DFHANDLER(togglesound)
268
DFHANDLER(rereadsounds)
277
* And executing an external program
279
static void Execute(const char *_s);
284
if(!Scr->NoGrabServer) {
288
XUngrabPointer(dpy, CurrentTime);
295
Execute(const char *_s)
308
/* Work on a local copy since we're mutating it */
314
/* Stash up current $DISPLAY value for resetting */
315
orig_display = getenv("DISPLAY");
319
* Build a display string using the current screen number, so that
320
* X programs which get fired up from a menu come up on the screen
321
* that they were invoked from, unless specifically overridden on
322
* their command line.
324
* Which is to say, given that we're on display "foo.bar:1.2", we
325
* want to translate that into "foo.bar:1.{Scr->screen}".
327
* We strdup() because DisplayString() is a macro returning into the
328
* dpy structure, and we're going to mutate the value we get from it.
330
_ds = DisplayString(dpy);
340
/* If it's not host:dpy, we don't have anything to do here */
341
colon = strrchr(ds, ':');
343
char *dot, *new_display;
345
/* Find the . in display.screen and chop it off */
346
dot = strchr(colon, '.');
351
/* Build a new string with our correct screen info */
352
asprintf(&new_display, "%s.%d", ds, Scr->screen);
359
setenv("DISPLAY", new_display, 1);
368
* We replace a couple placeholders in the string. $currentworkspace
369
* is documented in the manual; $redirect is not.
371
subs = strstr(s, "$currentworkspace");
376
wsname = GetCurrentWorkSpaceName(Scr->currentvs);
381
tmp = replace_substr(s, "$currentworkspace", wsname);
389
subs = strstr(s, "$redirect");
394
if(CLarg.is_captive) {
395
asprintf(&redir, "-xrm 'ctwm.redirect:%s'", Scr->captivename);
405
tmp = replace_substr(s, "$redirect", redir);
414
* Call it. Return value doesn't really matter, since whatever
415
* happened we're done. Maybe someday if we develop a "show user
416
* message" generalized func, we can tell the user if executing
423
* Restore $DISPLAY if we changed it. It's probably only necessary
424
* in edge cases (it might be used by ctwm restarting itself, for
425
* instance) and it's not quite clear whether the DisplayString()
426
* result would even be wrong for that, but what the heck, setenv()
431
setenv("DISPLAY", orig_display, 1);