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>
37 #include "WindowMaker.h"
47 #include "xmodifier.h"
51 /**** global variables *****/
53 extern char *DisplayName
;
55 extern WPreferences wPreferences
;
57 extern Time LastTimestamp
;
60 extern Atom _XA_DND_SELECTION
;
66 putdef(char *line
, char *name
, char *value
)
69 wwarning(_("could not define value for %s for cpp"), name
);
79 putidef(char *line
, char *name
, int value
)
82 sprintf(tmp
, "%i", value
);
97 user
= getpwuid(getuid());
99 wsyserror(_("could not get password entry for UID %i"), getuid());
102 if (!user
->pw_name
) {
105 return user
->pw_name
;
112 MakeCPPArgs(char *path
)
115 char buffer
[MAXLINE
], *buf
, *line
;
118 line
= wmalloc(MAXLINE
);
121 if ((buf
=getenv("HOSTNAME"))!=NULL
) {
123 wwarning(_("your machine is misconfigured. HOSTNAME is set to %s"),
126 putdef(line
, " -DHOST=", buf
);
127 } else if ((buf
=getenv("HOST"))!=NULL
) {
129 wwarning(_("your machine is misconfigured. HOST is set to %s"),
132 putdef(line
, " -DHOST=", buf
);
136 putdef(line
, " -DUSER=", buf
);
137 putidef(line
, " -DUID=", getuid());
138 buf
= XDisplayName(DisplayString(dpy
));
139 putdef(line
, " -DDISPLAY=", buf
);
140 putdef(line
, " -DWM_VERSION=", VERSION
);
142 visual
= DefaultVisual(dpy
, DefaultScreen(dpy
));
143 putidef(line
, " -DVISUAL=", visual
->class);
145 putidef(line
, " -DDEPTH=", DefaultDepth(dpy
, DefaultScreen(dpy
)));
147 putidef(line
, " -DSCR_WIDTH=", WidthOfScreen(DefaultScreenOfDisplay(dpy
)));
148 putidef(line
, " -DSCR_HEIGHT=",
149 HeightOfScreen(DefaultScreenOfDisplay(dpy
)));
152 strcpy(buffer
, path
);
153 buf
= strrchr(buffer
, '/');
154 if (buf
) *buf
= 0; /* trunc filename */
155 putdef(line
, " -I", buffer
);
160 /* this should be done just once, but it works this way */
161 strcpy(buffer
, DEF_CONFIG_PATHS
);
162 buf
= strtok(buffer
, ":");
165 char fullpath
[MAXLINE
];
168 strcpy(fullpath
, buf
);
170 char * wgethomedir();
171 /* home is statically allocated. Don't free it! */
172 char *home
= wgethomedir();
174 strcpy(fullpath
, home
);
175 strcat(fullpath
, &(buf
[1]));
178 putdef(line
, " -I", fullpath
);
180 } while ((buf
= strtok(NULL
, ":"))!=NULL
);
193 NextFocusWindow(WScreen
*scr
)
195 WWindow
*tmp
, *wwin
, *closest
, *min
;
198 if (!(wwin
= scr
->focused_window
))
205 if (wWindowCanReceiveFocus(tmp
)
206 && (!WFLAGP(tmp
, skip_window_list
)|| tmp
->flags
.internal_window
)) {
207 if (min
->client_win
> tmp
->client_win
)
209 if (tmp
->client_win
> wwin
->client_win
211 || (tmp
->client_win
- wwin
->client_win
) < d
)) {
213 d
= tmp
->client_win
- wwin
->client_win
;
218 if (!closest
||closest
==wwin
)
225 PrevFocusWindow(WScreen
*scr
)
227 WWindow
*tmp
, *wwin
, *closest
, *max
;
230 if (!(wwin
= scr
->focused_window
))
237 if (wWindowCanReceiveFocus(tmp
) &&
238 (!WFLAGP(tmp
, skip_window_list
) || tmp
->flags
.internal_window
)) {
239 if (max
->client_win
< tmp
->client_win
)
241 if (tmp
->client_win
< wwin
->client_win
243 || (wwin
->client_win
- tmp
->client_win
) < d
)) {
245 d
= wwin
->client_win
- tmp
->client_win
;
250 if (!closest
||closest
==wwin
)
259 * Is win2 below win1?
262 isBelow(WWindow
*win1
, WWindow
*win2
)
267 tmp
= win1
->frame
->core
->stacking
->under
;
269 if (tmp
== win2
->frame
->core
)
271 tmp
= tmp
->stacking
->under
;
274 for (i
=win1
->frame
->core
->stacking
->window_level
-1; i
>=0; i
--) {
275 tmp
= win1
->screen_ptr
->stacking_list
[i
];
277 if (tmp
== win2
->frame
->core
)
279 tmp
= tmp
->stacking
->under
;
292 Bool
wFetchName(dpy
, win
, winname
)
297 XTextProperty text_prop
;
301 if (XGetWMName(dpy
, win
, &text_prop
)) {
302 if (text_prop
.value
&& text_prop
.nitems
> 0) {
303 if (text_prop
.encoding
== XA_STRING
) {
304 *winname
= wstrdup((char *)text_prop
.value
);
305 XFree(text_prop
.value
);
307 text_prop
.nitems
= strlen((char *)text_prop
.value
);
308 if (XmbTextPropertyToTextList(dpy
, &text_prop
, &list
, &num
) >=
309 Success
&& num
> 0 && *list
) {
310 XFree(text_prop
.value
);
311 *winname
= wstrdup(*list
);
312 XFreeStringList(list
);
314 *winname
= wstrdup((char *)text_prop
.value
);
315 XFree(text_prop
.value
);
319 /* the title is set, but it was set to none */
320 *winname
= wstrdup("");
324 /* the hint is probably not set */
332 * XGetIconName Wrapper
336 Bool
wGetIconName(dpy
, win
, iconname
)
341 XTextProperty text_prop
;
345 if (XGetWMIconName(dpy
, win
, &text_prop
) != 0 && text_prop
.value
346 && text_prop
.nitems
> 0) {
347 if (text_prop
.encoding
== XA_STRING
)
348 *iconname
= (char *)text_prop
.value
;
350 text_prop
.nitems
= strlen((char *)text_prop
.value
);
351 if (XmbTextPropertyToTextList(dpy
, &text_prop
, &list
, &num
) >=
352 Success
&& num
> 0 && *list
) {
353 XFree(text_prop
.value
);
354 *iconname
= wstrdup(*list
);
355 XFreeStringList(list
);
357 *iconname
= (char *)text_prop
.value
;
369 wTextWidth(XFontSet font
, char *text
, int length
)
374 XmbTextExtents(font
, text
, length
, &AIXsucks
, &rec
);
380 wTextWidth(XFontStruct
*font
, char *text
, int length
)
382 return XTextWidth(font
, text
, length
);
392 /* compress all expose events into a single one */
394 if (XCheckMaskEvent(dpy
, ExposureMask
, &event
)) {
395 /* ignore other exposure events for this window */
396 while (XCheckWindowEvent(dpy
, event
.xexpose
.window
, ExposureMask
,
398 /* eat exposes for other windows */
401 event
.xexpose
.count
= 0;
402 XPutBackEvent(dpy
, &event
);
408 SlideWindow(Window win
, int from_x
, int from_y
, int to_x
, int to_y
)
410 time_t time0
= time(NULL
);
411 float dx
, dy
, x
=from_x
, y
=from_y
, sx
, sy
, px
, py
;
414 /* animation parameters */
420 {ICON_SLIDE_DELAY_UF
, ICON_SLIDE_STEPS_UF
, ICON_SLIDE_SLOWDOWN_UF
},
421 {ICON_SLIDE_DELAY_F
, ICON_SLIDE_STEPS_F
, ICON_SLIDE_SLOWDOWN_F
},
422 {ICON_SLIDE_DELAY_M
, ICON_SLIDE_STEPS_M
, ICON_SLIDE_SLOWDOWN_M
},
423 {ICON_SLIDE_DELAY_S
, ICON_SLIDE_STEPS_S
, ICON_SLIDE_SLOWDOWN_S
},
424 {ICON_SLIDE_DELAY_U
, ICON_SLIDE_STEPS_U
, ICON_SLIDE_SLOWDOWN_U
}};
428 dx
= (float)(to_x
-from_x
);
429 dy
= (float)(to_y
-from_y
);
430 sx
= (dx
== 0 ? 0 : fabs(dx
)/dx
);
431 sy
= (dy
== 0 ? 0 : fabs(dy
)/dy
);
433 if (fabs(dx
) > fabs(dy
)) {
438 px
= dx
/ apars
[(int)wPreferences
.icon_slide_speed
].slowdown
;
439 if (px
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
> 0)
440 px
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
441 else if (px
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
< 0)
442 px
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
443 py
= (sx
== 0 ? 0 : px
*dy
/dx
);
445 py
= dy
/ apars
[(int)wPreferences
.icon_slide_speed
].slowdown
;
446 if (py
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
> 0)
447 py
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
448 else if (py
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
< 0)
449 py
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
450 px
= (sy
== 0 ? 0 : py
*dx
/dy
);
453 while (x
!= to_x
|| y
!= to_y
) {
456 if ((px
<0 && (int)x
< to_x
) || (px
>0 && (int)x
> to_x
))
458 if ((py
<0 && (int)y
< to_y
) || (py
>0 && (int)y
> to_y
))
462 px
= px
* (1.0 - 1/(float)apars
[(int)wPreferences
.icon_slide_speed
].slowdown
);
463 if (px
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
> 0)
464 px
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
465 else if (px
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
< 0)
466 px
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
467 py
= (sx
== 0 ? 0 : px
*dy
/dx
);
469 py
= py
* (1.0 - 1/(float)apars
[(int)wPreferences
.icon_slide_speed
].slowdown
);
470 if (py
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
> 0)
471 py
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
472 else if (py
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
< 0)
473 py
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
474 px
= (sy
== 0 ? 0 : py
*dx
/dy
);
477 XMoveWindow(dpy
, win
, (int)x
, (int)y
);
479 if (apars
[(int)wPreferences
.icon_slide_speed
].delay
> 0) {
480 wusleep(apars
[(int)wPreferences
.icon_slide_speed
].delay
*1000L);
482 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
485 XMoveWindow(dpy
, win
, to_x
, to_y
);
488 /* compress expose events */
494 ShrinkString(WFont
*font
, char *string
, int width
)
505 return wstrdup(string
);
508 w
= wTextWidth(font
->font
, string
, p
);
509 text
= wmalloc(strlen(string
)+8);
510 strcpy(text
, string
);
514 pos
= strchr(text
, ' ');
516 pos
= strchr(text
, ':');
521 w1
=wTextWidth(font
->font
, text
, p
);
538 width
-= wTextWidth(font
->font
, "...", 3);
544 while (p2
>p1
&& p1
!=t
) {
545 w
= wTextWidth(font
->font
, &string
[p
-t
], t
);
549 } else if (w
<width
) {
555 strcat(text
, &string
[p
-p1
]);
562 FindImage(char *paths
, char *file
)
566 tmp
= strrchr(file
, ':');
569 path
= wfindfile(paths
, file
);
573 path
= wfindfile(paths
, file
);
581 FlattenStringList(char **list
, int count
)
584 char *flat_string
, *wspace
;
587 for (i
=0; i
<count
; i
++) {
588 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
589 j
+= strlen(list
[i
]);
590 if (strpbrk(list
[i
], " \t"))
595 flat_string
= malloc(j
+count
+1);
601 for (i
=0; i
<count
; i
++) {
602 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
604 strcat(flat_string
, " ");
605 wspace
= strpbrk(list
[i
], " \t");
607 strcat(flat_string
, "\"");
608 strcat(flat_string
, list
[i
]);
610 strcat(flat_string
, "\"");
620 *----------------------------------------------------------------------
622 * Divides a command line into a argv/argc pair.
623 *----------------------------------------------------------------------
638 static DFA mtable
[9][6] = {
639 {{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
640 {{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
641 {{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
642 {{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
643 {{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
644 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
645 {{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
646 {{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
647 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
651 next_token(char *word
, char **next
)
657 t
= ret
= wmalloc(strlen(word
)+1);
671 else if (*ptr
==' ' || *ptr
=='\t')
676 if (mtable
[state
][ctype
].output
) {
680 state
= mtable
[state
][ctype
].nstate
;
682 if (mtable
[state
][0].output
<0) {
704 ParseCommand(char *command
, char ***argv
, int *argc
)
706 LinkedList
*list
= NULL
;
712 token
= next_token(line
, &line
);
714 list
= list_cons(token
, list
);
716 } while (token
!=NULL
&& line
!=NULL
);
718 count
= list_length(list
);
719 *argv
= wmalloc(sizeof(char*)*count
);
722 (*argv
)[--i
] = list
->head
;
723 list_remove_head(&list
);
736 getselection(WScreen
*scr
)
739 extern char *W_GetTextSelection(); /* in WINGs */
741 tmp
= W_GetTextSelection(scr
->wmscreen
, XA_PRIMARY
);
743 tmp
= W_GetTextSelection(scr
->wmscreen
, XA_CUT_BUFFER0
);
752 puts("getting selection");
754 RequestSelection(dpy
, scr
->no_focus_win
, LastTimestamp
);
755 /* timeout on 1 sec. */
756 id
= WMAddTimerHandler(1000, timeup
, &timeover
);
758 WMNextEvent(dpy
, &event
);
759 if (event
.type
== SelectionNotify
760 && event
.xany
.window
==scr
->no_focus_win
) {
761 WMDeleteTimerHandler(id
);
763 puts("selection ok");
765 return GetSelection(dpy
, scr
->no_focus_win
);
767 WMHandleEvent(&event
);
770 wwarning(_("selection timed-out"));
777 getuserinput(WScreen
*scr
, char *line
, int *ptr
)
784 char tbuffer
[256], pbuffer
[256];
786 title
= _("Program Arguments");
787 prompt
= _("Enter command arguments:");
797 for (; line
[*ptr
]!=0 && state
!=_DONE
; (*ptr
)++) {
800 if (line
[*ptr
]=='(') {
809 if (j
<= 0 && line
[*ptr
]==',') {
813 strncpy(tbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
814 tbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
815 title
= (char*)tbuffer
;
820 } else if (j
<= 0 && line
[*ptr
]==')') {
823 strncpy(tbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
824 tbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
825 title
= (char*)tbuffer
;
829 } else if (line
[*ptr
]=='(') {
831 } else if (line
[*ptr
]==')') {
838 if (line
[*ptr
]==')' && j
==0) {
840 if (*ptr
-begin
> 1) {
841 strncpy(pbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
842 pbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
843 prompt
= (char*)pbuffer
;
846 } else if (line
[*ptr
]=='(')
848 else if (line
[*ptr
]==')')
859 if (!wInputDialog(scr
, title
, prompt
, &ret
))
868 get_dnd_selection(WScreen
*scr
)
870 XTextProperty text_ret
;
878 return (wstrdup(scr
->xdestring
));
881 result
=XGetTextProperty(dpy
, scr
->root_win
, &text_ret
, _XA_DND_SELECTION
);
883 if (result
==0 || text_ret
.value
==NULL
|| text_ret
.encoding
==None
884 || text_ret
.format
==0 || text_ret
.nitems
== 0) {
885 wwarning(_("unable to get dropped data from DND drop"));
889 XTextPropertyToStringList(&text_ret
, &list
, &count
);
891 if (!list
|| count
<1) {
892 XFree(text_ret
.value
);
893 wwarning(_("error getting dropped data from DND drop"));
897 flat_string
= FlattenStringList(list
, count
);
899 wwarning(_("out of memory while getting data from DND drop"));
902 XFreeStringList(list
);
903 XFree(text_ret
.value
);
906 #endif /* OFFIX_DND */
914 * state input new-state output
915 * NORMAL % OPTION <nil>
916 * NORMAL \ ESCAPE <nil>
917 * NORMAL etc. NORMAL <input>
918 * ESCAPE any NORMAL <input>
919 * OPTION s NORMAL <selection buffer>
920 * OPTION w NORMAL <selected window id>
921 * OPTION a NORMAL <input text>
922 * OPTION d NORMAL <OffiX DND selection object>
923 * OPTION W NORMAL <current workspace>
924 * OPTION etc. NORMAL %<input>
926 #define TMPBUFSIZE 64
928 ExpandOptions(WScreen
*scr
, char *cmdline
)
930 int ptr
, optr
, state
, len
, olen
;
932 char *selection
=NULL
;
933 char *user_input
=NULL
;
935 char *dropped_thing
=NULL
;
937 char tmpbuf
[TMPBUFSIZE
];
940 len
= strlen(cmdline
);
944 wwarning(_("out of memory during expansion of \"%s\""));
948 ptr
= 0; /* input line pointer */
949 optr
= 0; /* output line pointer */
954 switch (cmdline
[ptr
]) {
963 out
[optr
++]=cmdline
[ptr
];
968 switch (cmdline
[ptr
]) {
982 out
[optr
++]=cmdline
[ptr
];
988 switch (cmdline
[ptr
]) {
990 if (scr
->focused_window
991 && scr
->focused_window
->flags
.focused
) {
992 sprintf(tmpbuf
, "0x%x",
993 (unsigned int)scr
->focused_window
->client_win
);
994 slen
= strlen(tmpbuf
);
996 nout
= realloc(out
,olen
);
998 wwarning(_("out of memory during expansion of \"%w\""));
1010 sprintf(tmpbuf
, "0x%x",
1011 (unsigned int)scr
->current_workspace
+ 1);
1012 slen
= strlen(tmpbuf
);
1014 nout
= realloc(out
,olen
);
1016 wwarning(_("out of memory during expansion of \"%W\""));
1026 user_input
= getuserinput(scr
, cmdline
, &ptr
);
1028 slen
= strlen(user_input
);
1030 nout
= realloc(out
,olen
);
1032 wwarning(_("out of memory during expansion of \"%a\""));
1036 strcat(out
,user_input
);
1039 /* Not an error, but user has Canceled the dialog box.
1040 * This will make the command to not be performed. */
1047 if (!dropped_thing
) {
1048 dropped_thing
= get_dnd_selection(scr
);
1050 if (!dropped_thing
) {
1051 scr
->flags
.dnd_data_convertion_status
= 1;
1054 slen
= strlen(dropped_thing
);
1056 nout
= realloc(out
,olen
);
1058 wwarning(_("out of memory during expansion of \"%d\""));
1062 strcat(out
,dropped_thing
);
1065 #endif /* OFFIX_DND */
1069 selection
= getselection(scr
);
1072 wwarning(_("selection not available"));
1075 slen
= strlen(selection
);
1077 nout
= realloc(out
,olen
);
1079 wwarning(_("out of memory during expansion of \"%s\""));
1083 strcat(out
,selection
);
1088 out
[optr
++]=cmdline
[ptr
];
1107 /* We don't care for upper/lower case in comparing the keys; so we
1108 have to define our own comparison function here */
1110 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
1114 str1
= PLGetString(pl1
);
1115 str2
= PLGetString(pl2
);
1117 if (strcasecmp(str1
, str2
)==0)
1124 /* feof doesn't seem to work on pipes */
1126 IsEof(FILE * stream
)
1128 static struct stat stinfo
;
1130 fstat(fileno(stream
), &stinfo
);
1131 return ((S_ISFIFO(stinfo
.st_dev
) && stinfo
.st_size
== 0) ||
1137 ParseWindowName(proplist_t value
, char **winstance
, char **wclass
, char *where
)
1141 *winstance
= *wclass
= NULL
;
1143 if (!PLIsString(value
)) {
1144 wwarning(_("bad window name value in %s state info"), where
);
1148 name
= PLGetString(value
);
1149 if (!name
|| strlen(name
)==0) {
1150 wwarning(_("bad window name value in %s state info"), where
);
1154 UnescapeWM_CLASS(name
, winstance
, wclass
);
1160 keysymToString(KeySym keysym
, unsigned int state
)
1163 char *buf
= wmalloc(20);
1167 kev
.type
= KeyPress
;
1168 kev
.send_event
= False
;
1169 kev
.window
= DefaultRootWindow(dpy
);
1170 kev
.root
= DefaultRootWindow(dpy
);
1171 kev
.same_screen
= True
;
1172 kev
.subwindow
= kev
.root
;
1173 kev
.serial
= 0x12344321;
1174 kev
.time
= CurrentTime
;
1176 kev
.keycode
= XKeysymToKeycode(dpy
, keysym
);
1177 count
= XLookupString(&kev
, buf
, 19, NULL
, NULL
);
1185 GetShortcutString(char *text
)
1187 char *buffer
= NULL
;
1194 tmp
= text
= wstrdup(text
);
1197 while ((k
= strchr(text
, '+'))!=NULL
) {
1201 mod
= wXModifierFromKey(text
);
1203 return wstrdup("bug");
1208 if (strcasecmp(text
, "Meta")==0) {
1209 buffer
= wstrappend(buffer
, "M+");
1210 } else if (strcasecmp(text
, "Alt")==0) {
1211 buffer
= wstrappend(buffer
, "A+");
1212 } else if (strcasecmp(text
, "Shift")==0) {
1213 buffer
= wstrappend(buffer
, "Sh+");
1214 } else if (strcasecmp(text
, "Mod1")==0) {
1215 buffer
= wstrappend(buffer
, "M1+");
1216 } else if (strcasecmp(text
, "Mod2")==0) {
1217 buffer
= wstrappend(buffer
, "M2+");
1218 } else if (strcasecmp(text
, "Mod3")==0) {
1219 buffer
= wstrappend(buffer
, "M3+");
1220 } else if (strcasecmp(text
, "Mod4")==0) {
1221 buffer
= wstrappend(buffer
, "M4+");
1222 } else if (strcasecmp(text
, "Mod5")==0) {
1223 buffer
= wstrappend(buffer
, "M5+");
1224 } else if (strcasecmp(text
, "Control")==0) {
1227 buffer
= wstrappend(buffer
, text
);
1233 buffer
= wstrappend(buffer
, "^");
1235 buffer
= wstrappend(buffer
, text
);
1238 /* ksym = XStringToKeysym(text);
1239 tmp = keysymToString(ksym, modmask);
1241 buffer = wstrappend(buffer, tmp);
1250 EscapeWM_CLASS(char *name
, char *class)
1253 char *ename
= NULL
, *eclass
= NULL
;
1256 if (!name
&& !class)
1261 ename
= wmalloc(l
*2);
1263 for (i
=0; i
<l
; i
++) {
1264 if (name
[i
]=='\\') {
1266 } else if (name
[i
]=='.') {
1269 ename
[j
++] = name
[i
];
1275 eclass
= wmalloc(l
*2);
1277 for (i
=0; i
<l
; i
++) {
1278 if (class[i
]=='\\') {
1280 } else if (class[i
]=='.') {
1283 eclass
[j
++] = class[i
];
1288 if (ename
&& eclass
) {
1289 ret
= wmalloc(strlen(ename
)+strlen(eclass
)+4);
1290 sprintf(ret
, "%s.%s", ename
, eclass
);
1294 ret
= wstrdup(ename
);
1297 ret
= wstrdup(eclass
);
1306 UnescapeWM_CLASS(char *str
, char **name
, char **class)
1314 *class = wmalloc(j
);
1317 /* separate string in 2 parts */
1320 for (i
= 0; i
< j
; i
++) {
1324 } else if (str
[i
]=='.') {
1333 /* unescape strings */
1336 for (i
= 0; i
< dot
; i
++) {
1341 (*name
)[k
++] = str
[i
];
1344 (*name
)[k
++] = str
[i
];
1352 for (i
= dot
+1; i
<j
; i
++) {
1357 (*class)[k
++] = str
[i
];
1378 SendHelperMessage(WScreen
*scr
, char type
, int workspace
, char *msg
)
1380 unsigned char *buffer
;
1385 if (!scr
->flags
.backimage_helper_launched
) {
1389 len
= (msg
? strlen(msg
) : 0) + (workspace
>=0 ? 4 : 0) + 1 ;
1390 buffer
= wmalloc(len
+5);
1391 sprintf(buf
, "%4i", len
);
1392 memcpy(buffer
, buf
, 4);
1395 if (workspace
>= 0) {
1396 sprintf(buf
, "%4i", workspace
);
1397 memcpy(&buffer
[i
], buf
, 4);
1402 strcpy(&buffer
[i
], msg
);
1404 if (write(scr
->helper_fd
, buffer
, len
+4) < 0) {
1405 wsyserror(_("could not send message to background image helper"));
1412 ExecuteShellCommand(WScreen
*scr
, char *command
)
1414 static char *shell
= NULL
;
1418 * This have a problem: if the shell is tcsh (not sure about others)
1419 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
1420 * will block and the command will not be executed.
1422 shell = getenv("SHELL");
1432 SetupEnvironment(scr
);
1437 execl(shell
, shell
, "-c", command
, NULL
);
1438 wsyserror("could not execute %s -c %s", shell
, command
);
1440 } else if (pid
< 0) {
1441 wsyserror("cannot fork a new process");