2 * Window Maker window manager
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
24 #include <X11/Xutil.h>
25 #include <X11/Xatom.h>
39 #include "WindowMaker.h"
49 #include "xmodifier.h"
53 /**** global variables *****/
55 extern char *DisplayName
;
57 extern WPreferences wPreferences
;
59 extern Time LastTimestamp
;
62 extern Atom _XA_DND_SELECTION
;
68 putdef(char *line
, char *name
, char *value
)
71 wwarning(_("could not define value for %s for cpp"), name
);
81 putidef(char *line
, char *name
, int value
)
84 sprintf(tmp
, "%i", value
);
99 user
= getpwuid(getuid());
101 wsyserror(_("could not get password entry for UID %i"), getuid());
104 if (!user
->pw_name
) {
107 return user
->pw_name
;
114 MakeCPPArgs(char *path
)
117 char buffer
[MAXLINE
], *buf
, *line
;
120 line
= wmalloc(MAXLINE
);
123 if ((buf
=getenv("HOSTNAME"))!=NULL
) {
125 wwarning(_("your machine is misconfigured. HOSTNAME is set to %s"),
128 putdef(line
, " -DHOST=", buf
);
129 } else if ((buf
=getenv("HOST"))!=NULL
) {
131 wwarning(_("your machine is misconfigured. HOST is set to %s"),
134 putdef(line
, " -DHOST=", buf
);
138 putdef(line
, " -DUSER=", buf
);
139 putidef(line
, " -DUID=", getuid());
140 buf
= XDisplayName(DisplayString(dpy
));
141 putdef(line
, " -DDISPLAY=", buf
);
142 putdef(line
, " -DWM_VERSION=", VERSION
);
144 visual
= DefaultVisual(dpy
, DefaultScreen(dpy
));
145 putidef(line
, " -DVISUAL=", visual
->class);
147 putidef(line
, " -DDEPTH=", DefaultDepth(dpy
, DefaultScreen(dpy
)));
149 putidef(line
, " -DSCR_WIDTH=", WidthOfScreen(DefaultScreenOfDisplay(dpy
)));
150 putidef(line
, " -DSCR_HEIGHT=",
151 HeightOfScreen(DefaultScreenOfDisplay(dpy
)));
154 strcpy(buffer
, path
);
155 buf
= strrchr(buffer
, '/');
156 if (buf
) *buf
= 0; /* trunc filename */
157 putdef(line
, " -I", buffer
);
162 /* this should be done just once, but it works this way */
163 strcpy(buffer
, DEF_CONFIG_PATHS
);
164 buf
= strtok(buffer
, ":");
167 char fullpath
[MAXLINE
];
170 strcpy(fullpath
, buf
);
172 char * wgethomedir();
173 /* home is statically allocated. Don't free it! */
174 char *home
= wgethomedir();
176 strcpy(fullpath
, home
);
177 strcat(fullpath
, &(buf
[1]));
180 putdef(line
, " -I", fullpath
);
182 } while ((buf
= strtok(NULL
, ":"))!=NULL
);
195 NextFocusWindow(WScreen
*scr
)
197 WWindow
*tmp
, *wwin
, *closest
, *min
;
200 if (!(wwin
= scr
->focused_window
))
207 if (wWindowCanReceiveFocus(tmp
)
208 && (!WFLAGP(tmp
, skip_window_list
)|| tmp
->flags
.internal_window
)) {
209 if (min
->client_win
> tmp
->client_win
)
211 if (tmp
->client_win
> wwin
->client_win
213 || (tmp
->client_win
- wwin
->client_win
) < d
)) {
215 d
= tmp
->client_win
- wwin
->client_win
;
220 if (!closest
||closest
==wwin
)
227 PrevFocusWindow(WScreen
*scr
)
229 WWindow
*tmp
, *wwin
, *closest
, *max
;
232 if (!(wwin
= scr
->focused_window
))
239 if (wWindowCanReceiveFocus(tmp
) &&
240 (!WFLAGP(tmp
, skip_window_list
) || tmp
->flags
.internal_window
)) {
241 if (max
->client_win
< tmp
->client_win
)
243 if (tmp
->client_win
< wwin
->client_win
245 || (wwin
->client_win
- tmp
->client_win
) < d
)) {
247 d
= wwin
->client_win
- tmp
->client_win
;
252 if (!closest
||closest
==wwin
)
261 * Is win2 below win1?
264 isBelow(WWindow
*win1
, WWindow
*win2
)
269 tmp
= win1
->frame
->core
->stacking
->under
;
271 if (tmp
== win2
->frame
->core
)
273 tmp
= tmp
->stacking
->under
;
276 for (i
=win1
->frame
->core
->stacking
->window_level
-1; i
>=0; i
--) {
277 tmp
= win1
->screen_ptr
->stacking_list
[i
];
279 if (tmp
== win2
->frame
->core
)
281 tmp
= tmp
->stacking
->under
;
294 Bool
wFetchName(dpy
, win
, winname
)
299 XTextProperty text_prop
;
303 if (XGetWMName(dpy
, win
, &text_prop
)) {
304 if (text_prop
.value
&& text_prop
.nitems
> 0) {
305 if (text_prop
.encoding
== XA_STRING
) {
306 *winname
= wstrdup((char *)text_prop
.value
);
307 XFree(text_prop
.value
);
309 text_prop
.nitems
= strlen((char *)text_prop
.value
);
310 if (XmbTextPropertyToTextList(dpy
, &text_prop
, &list
, &num
) >=
311 Success
&& num
> 0 && *list
) {
312 XFree(text_prop
.value
);
313 *winname
= wstrdup(*list
);
314 XFreeStringList(list
);
316 *winname
= wstrdup((char *)text_prop
.value
);
317 XFree(text_prop
.value
);
321 /* the title is set, but it was set to none */
322 *winname
= wstrdup("");
326 /* the hint is probably not set */
334 * XGetIconName Wrapper
338 Bool
wGetIconName(dpy
, win
, iconname
)
343 XTextProperty text_prop
;
347 if (XGetWMIconName(dpy
, win
, &text_prop
) != 0 && text_prop
.value
348 && text_prop
.nitems
> 0) {
349 if (text_prop
.encoding
== XA_STRING
)
350 *iconname
= (char *)text_prop
.value
;
352 text_prop
.nitems
= strlen((char *)text_prop
.value
);
353 if (XmbTextPropertyToTextList(dpy
, &text_prop
, &list
, &num
) >=
354 Success
&& num
> 0 && *list
) {
355 XFree(text_prop
.value
);
356 *iconname
= wstrdup(*list
);
357 XFreeStringList(list
);
359 *iconname
= (char *)text_prop
.value
;
371 wTextWidth(XFontSet font
, char *text
, int length
)
376 XmbTextExtents(font
, text
, length
, &AIXsucks
, &rec
);
382 wTextWidth(XFontStruct
*font
, char *text
, int length
)
384 return XTextWidth(font
, text
, length
);
394 /* compress all expose events into a single one */
396 if (XCheckMaskEvent(dpy
, ExposureMask
, &event
)) {
397 /* ignore other exposure events for this window */
398 while (XCheckWindowEvent(dpy
, event
.xexpose
.window
, ExposureMask
,
400 /* eat exposes for other windows */
403 event
.xexpose
.count
= 0;
404 XPutBackEvent(dpy
, &event
);
410 SlideWindow(Window win
, int from_x
, int from_y
, int to_x
, int to_y
)
412 time_t time0
= time(NULL
);
413 float dx
, dy
, x
=from_x
, y
=from_y
, sx
, sy
, px
, py
;
416 /* animation parameters */
422 {ICON_SLIDE_DELAY_UF
, ICON_SLIDE_STEPS_UF
, ICON_SLIDE_SLOWDOWN_UF
},
423 {ICON_SLIDE_DELAY_F
, ICON_SLIDE_STEPS_F
, ICON_SLIDE_SLOWDOWN_F
},
424 {ICON_SLIDE_DELAY_M
, ICON_SLIDE_STEPS_M
, ICON_SLIDE_SLOWDOWN_M
},
425 {ICON_SLIDE_DELAY_S
, ICON_SLIDE_STEPS_S
, ICON_SLIDE_SLOWDOWN_S
},
426 {ICON_SLIDE_DELAY_U
, ICON_SLIDE_STEPS_U
, ICON_SLIDE_SLOWDOWN_U
}};
430 dx
= (float)(to_x
-from_x
);
431 dy
= (float)(to_y
-from_y
);
432 sx
= (dx
== 0 ? 0 : fabs(dx
)/dx
);
433 sy
= (dy
== 0 ? 0 : fabs(dy
)/dy
);
435 if (fabs(dx
) > fabs(dy
)) {
440 px
= dx
/ apars
[(int)wPreferences
.icon_slide_speed
].slowdown
;
441 if (px
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
> 0)
442 px
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
443 else if (px
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
< 0)
444 px
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
445 py
= (sx
== 0 ? 0 : px
*dy
/dx
);
447 py
= dy
/ apars
[(int)wPreferences
.icon_slide_speed
].slowdown
;
448 if (py
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
> 0)
449 py
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
450 else if (py
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
< 0)
451 py
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
452 px
= (sy
== 0 ? 0 : py
*dx
/dy
);
455 while (x
!= to_x
|| y
!= to_y
) {
458 if ((px
<0 && (int)x
< to_x
) || (px
>0 && (int)x
> to_x
))
460 if ((py
<0 && (int)y
< to_y
) || (py
>0 && (int)y
> to_y
))
464 px
= px
* (1.0 - 1/(float)apars
[(int)wPreferences
.icon_slide_speed
].slowdown
);
465 if (px
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
> 0)
466 px
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
467 else if (px
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
< 0)
468 px
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
469 py
= (sx
== 0 ? 0 : px
*dy
/dx
);
471 py
= py
* (1.0 - 1/(float)apars
[(int)wPreferences
.icon_slide_speed
].slowdown
);
472 if (py
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
> 0)
473 py
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
474 else if (py
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
< 0)
475 py
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
476 px
= (sy
== 0 ? 0 : py
*dx
/dy
);
479 XMoveWindow(dpy
, win
, (int)x
, (int)y
);
481 if (apars
[(int)wPreferences
.icon_slide_speed
].delay
> 0) {
482 wusleep(apars
[(int)wPreferences
.icon_slide_speed
].delay
*1000L);
484 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
487 XMoveWindow(dpy
, win
, to_x
, to_y
);
490 /* compress expose events */
496 ShrinkString(WFont
*font
, char *string
, int width
)
507 return wstrdup(string
);
510 w
= wTextWidth(font
->font
, string
, p
);
511 text
= wmalloc(strlen(string
)+8);
512 strcpy(text
, string
);
516 pos
= strchr(text
, ' ');
518 pos
= strchr(text
, ':');
523 w1
=wTextWidth(font
->font
, text
, p
);
540 width
-= wTextWidth(font
->font
, "...", 3);
546 while (p2
>p1
&& p1
!=t
) {
547 w
= wTextWidth(font
->font
, &string
[p
-t
], t
);
551 } else if (w
<width
) {
557 strcat(text
, &string
[p
-p1
]);
564 FindImage(char *paths
, char *file
)
568 tmp
= strrchr(file
, ':');
571 path
= wfindfile(paths
, file
);
575 path
= wfindfile(paths
, file
);
583 FlattenStringList(char **list
, int count
)
586 char *flat_string
, *wspace
;
589 for (i
=0; i
<count
; i
++) {
590 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
591 j
+= strlen(list
[i
]);
592 if (strpbrk(list
[i
], " \t"))
597 flat_string
= malloc(j
+count
+1);
603 for (i
=0; i
<count
; i
++) {
604 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
606 strcat(flat_string
, " ");
607 wspace
= strpbrk(list
[i
], " \t");
609 strcat(flat_string
, "\"");
610 strcat(flat_string
, list
[i
]);
612 strcat(flat_string
, "\"");
622 *----------------------------------------------------------------------
624 * Divides a command line into a argv/argc pair.
625 *----------------------------------------------------------------------
640 static DFA mtable
[9][6] = {
641 {{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
642 {{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
643 {{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
644 {{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
645 {{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
646 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
647 {{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
648 {{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
649 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
653 next_token(char *word
, char **next
)
659 t
= ret
= wmalloc(strlen(word
)+1);
673 else if (*ptr
==' ' || *ptr
=='\t')
678 if (mtable
[state
][ctype
].output
) {
682 state
= mtable
[state
][ctype
].nstate
;
684 if (mtable
[state
][0].output
<0) {
706 ParseCommand(char *command
, char ***argv
, int *argc
)
708 LinkedList
*list
= NULL
;
714 token
= next_token(line
, &line
);
716 list
= list_cons(token
, list
);
718 } while (token
!=NULL
&& line
!=NULL
);
720 count
= list_length(list
);
721 *argv
= wmalloc(sizeof(char*)*count
);
724 (*argv
)[--i
] = list
->head
;
725 list_remove_head(&list
);
738 getselection(WScreen
*scr
)
741 extern char *W_GetTextSelection(); /* in WINGs */
743 tmp
= W_GetTextSelection(scr
->wmscreen
, XA_PRIMARY
);
745 tmp
= W_GetTextSelection(scr
->wmscreen
, XA_CUT_BUFFER0
);
754 puts("getting selection");
756 RequestSelection(dpy
, scr
->no_focus_win
, LastTimestamp
);
757 /* timeout on 1 sec. */
758 id
= WMAddTimerHandler(1000, timeup
, &timeover
);
760 WMNextEvent(dpy
, &event
);
761 if (event
.type
== SelectionNotify
762 && event
.xany
.window
==scr
->no_focus_win
) {
763 WMDeleteTimerHandler(id
);
765 puts("selection ok");
767 return GetSelection(dpy
, scr
->no_focus_win
);
769 WMHandleEvent(&event
);
772 wwarning(_("selection timed-out"));
779 getuserinput(WScreen
*scr
, char *line
, int *ptr
)
786 char tbuffer
[256], pbuffer
[256];
788 title
= _("Program Arguments");
789 prompt
= _("Enter command arguments:");
799 for (; line
[*ptr
]!=0 && state
!=_DONE
; (*ptr
)++) {
802 if (line
[*ptr
]=='(') {
811 if (j
<= 0 && line
[*ptr
]==',') {
815 strncpy(tbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
816 tbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
817 title
= (char*)tbuffer
;
822 } else if (j
<= 0 && line
[*ptr
]==')') {
825 strncpy(tbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
826 tbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
827 title
= (char*)tbuffer
;
831 } else if (line
[*ptr
]=='(') {
833 } else if (line
[*ptr
]==')') {
840 if (line
[*ptr
]==')' && j
==0) {
842 if (*ptr
-begin
> 1) {
843 strncpy(pbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
844 pbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
845 prompt
= (char*)pbuffer
;
848 } else if (line
[*ptr
]=='(')
850 else if (line
[*ptr
]==')')
861 if (!wInputDialog(scr
, title
, prompt
, &ret
))
870 get_dnd_selection(WScreen
*scr
)
872 XTextProperty text_ret
;
881 printf(" return %s\n",scr->xdestring);
883 return (wstrdup(scr
->xdestring
));
886 result
=XGetTextProperty(dpy
, scr
->root_win
, &text_ret
, _XA_DND_SELECTION
);
888 if (result
==0 || text_ret
.value
==NULL
|| text_ret
.encoding
==None
889 || text_ret
.format
==0 || text_ret
.nitems
== 0) {
890 wwarning(_("unable to get dropped data from DND drop"));
894 XTextPropertyToStringList(&text_ret
, &list
, &count
);
896 if (!list
|| count
<1) {
897 XFree(text_ret
.value
);
898 wwarning(_("error getting dropped data from DND drop"));
902 flat_string
= FlattenStringList(list
, count
);
904 wwarning(_("out of memory while getting data from DND drop"));
907 XFreeStringList(list
);
908 XFree(text_ret
.value
);
911 #endif /* OFFIX_DND */
919 * state input new-state output
920 * NORMAL % OPTION <nil>
921 * NORMAL \ ESCAPE <nil>
922 * NORMAL etc. NORMAL <input>
923 * ESCAPE any NORMAL <input>
924 * OPTION s NORMAL <selection buffer>
925 * OPTION w NORMAL <selected window id>
926 * OPTION a NORMAL <input text>
927 * OPTION d NORMAL <OffiX DND selection object>
928 * OPTION W NORMAL <current workspace>
929 * OPTION etc. NORMAL %<input>
931 #define TMPBUFSIZE 64
933 ExpandOptions(WScreen
*scr
, char *cmdline
)
935 int ptr
, optr
, state
, len
, olen
;
937 char *selection
=NULL
;
938 char *user_input
=NULL
;
940 char *dropped_thing
=NULL
;
942 char tmpbuf
[TMPBUFSIZE
];
945 len
= strlen(cmdline
);
949 wwarning(_("out of memory during expansion of \"%s\""));
953 ptr
= 0; /* input line pointer */
954 optr
= 0; /* output line pointer */
959 switch (cmdline
[ptr
]) {
968 out
[optr
++]=cmdline
[ptr
];
973 switch (cmdline
[ptr
]) {
987 out
[optr
++]=cmdline
[ptr
];
993 switch (cmdline
[ptr
]) {
995 if (scr
->focused_window
996 && scr
->focused_window
->flags
.focused
) {
997 sprintf(tmpbuf
, "0x%x",
998 (unsigned int)scr
->focused_window
->client_win
);
999 slen
= strlen(tmpbuf
);
1001 nout
= realloc(out
,olen
);
1003 wwarning(_("out of memory during expansion of \"%w\""));
1015 sprintf(tmpbuf
, "0x%x",
1016 (unsigned int)scr
->current_workspace
+ 1);
1017 slen
= strlen(tmpbuf
);
1019 nout
= realloc(out
,olen
);
1021 wwarning(_("out of memory during expansion of \"%W\""));
1031 user_input
= getuserinput(scr
, cmdline
, &ptr
);
1033 slen
= strlen(user_input
);
1035 nout
= realloc(out
,olen
);
1037 wwarning(_("out of memory during expansion of \"%a\""));
1041 strcat(out
,user_input
);
1044 /* Not an error, but user has Canceled the dialog box.
1045 * This will make the command to not be performed. */
1052 if (!dropped_thing
) {
1053 dropped_thing
= get_dnd_selection(scr
);
1055 if (!dropped_thing
) {
1056 scr
->flags
.dnd_data_convertion_status
= 1;
1059 slen
= strlen(dropped_thing
);
1061 nout
= realloc(out
,olen
);
1063 wwarning(_("out of memory during expansion of \"%d\""));
1067 strcat(out
,dropped_thing
);
1070 #endif /* OFFIX_DND */
1074 selection
= getselection(scr
);
1077 wwarning(_("selection not available"));
1080 slen
= strlen(selection
);
1082 nout
= realloc(out
,olen
);
1084 wwarning(_("out of memory during expansion of \"%s\""));
1088 strcat(out
,selection
);
1093 out
[optr
++]=cmdline
[ptr
];
1112 /* We don't care for upper/lower case in comparing the keys; so we
1113 have to define our own comparison function here */
1115 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
1119 str1
= PLGetString(pl1
);
1120 str2
= PLGetString(pl2
);
1122 if (strcasecmp(str1
, str2
)==0)
1129 /* feof doesn't seem to work on pipes */
1131 IsEof(FILE * stream
)
1133 static struct stat stinfo
;
1135 fstat(fileno(stream
), &stinfo
);
1136 return ((S_ISFIFO(stinfo
.st_dev
) && stinfo
.st_size
== 0) ||
1142 ParseWindowName(proplist_t value
, char **winstance
, char **wclass
, char *where
)
1146 *winstance
= *wclass
= NULL
;
1148 if (!PLIsString(value
)) {
1149 wwarning(_("bad window name value in %s state info"), where
);
1153 name
= PLGetString(value
);
1154 if (!name
|| strlen(name
)==0) {
1155 wwarning(_("bad window name value in %s state info"), where
);
1159 UnescapeWM_CLASS(name
, winstance
, wclass
);
1165 keysymToString(KeySym keysym
, unsigned int state
)
1168 char *buf
= wmalloc(20);
1172 kev
.type
= KeyPress
;
1173 kev
.send_event
= False
;
1174 kev
.window
= DefaultRootWindow(dpy
);
1175 kev
.root
= DefaultRootWindow(dpy
);
1176 kev
.same_screen
= True
;
1177 kev
.subwindow
= kev
.root
;
1178 kev
.serial
= 0x12344321;
1179 kev
.time
= CurrentTime
;
1181 kev
.keycode
= XKeysymToKeycode(dpy
, keysym
);
1182 count
= XLookupString(&kev
, buf
, 19, NULL
, NULL
);
1190 GetShortcutString(char *text
)
1192 char *buffer
= NULL
;
1199 tmp
= text
= wstrdup(text
);
1202 while ((k
= strchr(text
, '+'))!=NULL
) {
1206 mod
= wXModifierFromKey(text
);
1208 return wstrdup("bug");
1213 if (strcasecmp(text
, "Meta")==0) {
1214 buffer
= wstrappend(buffer
, "M+");
1215 } else if (strcasecmp(text
, "Alt")==0) {
1216 buffer
= wstrappend(buffer
, "A+");
1217 } else if (strcasecmp(text
, "Shift")==0) {
1218 buffer
= wstrappend(buffer
, "Sh+");
1219 } else if (strcasecmp(text
, "Mod1")==0) {
1220 buffer
= wstrappend(buffer
, "M1+");
1221 } else if (strcasecmp(text
, "Mod2")==0) {
1222 buffer
= wstrappend(buffer
, "M2+");
1223 } else if (strcasecmp(text
, "Mod3")==0) {
1224 buffer
= wstrappend(buffer
, "M3+");
1225 } else if (strcasecmp(text
, "Mod4")==0) {
1226 buffer
= wstrappend(buffer
, "M4+");
1227 } else if (strcasecmp(text
, "Mod5")==0) {
1228 buffer
= wstrappend(buffer
, "M5+");
1229 } else if (strcasecmp(text
, "Control")==0) {
1232 buffer
= wstrappend(buffer
, text
);
1238 buffer
= wstrappend(buffer
, "^");
1240 buffer
= wstrappend(buffer
, text
);
1243 /* ksym = XStringToKeysym(text);
1244 tmp = keysymToString(ksym, modmask);
1246 buffer = wstrappend(buffer, tmp);
1255 EscapeWM_CLASS(char *name
, char *class)
1258 char *ename
= NULL
, *eclass
= NULL
;
1261 if (!name
&& !class)
1266 ename
= wmalloc(l
*2);
1268 for (i
=0; i
<l
; i
++) {
1269 if (name
[i
]=='\\') {
1271 } else if (name
[i
]=='.') {
1274 ename
[j
++] = name
[i
];
1280 eclass
= wmalloc(l
*2);
1282 for (i
=0; i
<l
; i
++) {
1283 if (class[i
]=='\\') {
1285 } else if (class[i
]=='.') {
1288 eclass
[j
++] = class[i
];
1293 if (ename
&& eclass
) {
1294 ret
= wmalloc(strlen(ename
)+strlen(eclass
)+4);
1295 sprintf(ret
, "%s.%s", ename
, eclass
);
1299 ret
= wstrdup(ename
);
1302 ret
= wstrdup(eclass
);
1311 UnescapeWM_CLASS(char *str
, char **name
, char **class)
1319 *class = wmalloc(j
);
1322 /* separate string in 2 parts */
1325 for (i
= 0; i
< j
; i
++) {
1329 } else if (str
[i
]=='.') {
1338 /* unescape strings */
1341 for (i
= 0; i
< dot
; i
++) {
1346 (*name
)[k
++] = str
[i
];
1349 (*name
)[k
++] = str
[i
];
1357 for (i
= dot
+1; i
<j
; i
++) {
1362 (*class)[k
++] = str
[i
];
1383 SendHelperMessage(WScreen
*scr
, char type
, int workspace
, char *msg
)
1385 unsigned char *buffer
;
1390 if (!scr
->flags
.backimage_helper_launched
) {
1394 len
= (msg
? strlen(msg
) : 0) + (workspace
>=0 ? 4 : 0) + 1 ;
1395 buffer
= wmalloc(len
+5);
1396 sprintf(buf
, "%4i", len
);
1397 memcpy(buffer
, buf
, 4);
1400 if (workspace
>= 0) {
1401 sprintf(buf
, "%4i", workspace
);
1402 memcpy(&buffer
[i
], buf
, 4);
1407 strcpy(&buffer
[i
], msg
);
1409 if (write(scr
->helper_fd
, buffer
, len
+4) < 0) {
1410 wsyserror(_("could not send message to background image helper"));
1417 ExecuteShellCommand(WScreen
*scr
, char *command
)
1419 static char *shell
= NULL
;
1423 * This have a problem: if the shell is tcsh (not sure about others)
1424 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
1425 * will block and the command will not be executed.
1427 shell = getenv("SHELL");
1437 SetupEnvironment(scr
);
1442 execl(shell
, shell
, "-c", command
, NULL
);
1443 wsyserror("could not execute %s -c %s", shell
, command
);
1445 } else if (pid
< 0) {
1446 wsyserror("cannot fork a new process");