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>
40 #include "WindowMaker.h"
50 #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
;
121 line
= wmalloc(MAXLINE
);
124 if ((buf
=getenv("HOSTNAME"))!=NULL
) {
126 wwarning(_("your machine is misconfigured. HOSTNAME is set to %s"),
129 putdef(line
, " -DHOST=", buf
);
130 } else if ((buf
=getenv("HOST"))!=NULL
) {
132 wwarning(_("your machine is misconfigured. HOST is set to %s"),
135 putdef(line
, " -DHOST=", buf
);
139 putdef(line
, " -DUSER=", buf
);
140 putidef(line
, " -DUID=", getuid());
141 buf
= XDisplayName(DisplayString(dpy
));
142 putdef(line
, " -DDISPLAY=", buf
);
143 putdef(line
, " -DWM_VERSION=", VERSION
);
145 visual
= DefaultVisual(dpy
, DefaultScreen(dpy
));
146 putidef(line
, " -DVISUAL=", visual
->class);
148 putidef(line
, " -DDEPTH=", DefaultDepth(dpy
, DefaultScreen(dpy
)));
150 putidef(line
, " -DSCR_WIDTH=", WidthOfScreen(DefaultScreenOfDisplay(dpy
)));
151 putidef(line
, " -DSCR_HEIGHT=",
152 HeightOfScreen(DefaultScreenOfDisplay(dpy
)));
154 /* put the dir where the menu is being read from to the
158 buf
= strrchr(tmp
, '/');
159 if (buf
) *buf
= 0; /* trunc filename */
160 putdef(line
, " -I", tmp
);
165 /* this should be done just once, but it works this way */
166 strcpy(buffer
, DEF_CONFIG_PATHS
);
167 buf
= strtok(buffer
, ":");
170 char fullpath
[MAXLINE
];
173 strcpy(fullpath
, buf
);
175 char * wgethomedir();
176 /* home is statically allocated. Don't free it! */
177 char *home
= wgethomedir();
179 strcpy(fullpath
, home
);
180 strcat(fullpath
, &(buf
[1]));
183 putdef(line
, " -I", fullpath
);
185 } while ((buf
= strtok(NULL
, ":"))!=NULL
);
198 NextFocusWindow(WScreen
*scr
)
200 WWindow
*tmp
, *wwin
, *closest
, *min
;
203 if (!(wwin
= scr
->focused_window
))
210 if (wWindowCanReceiveFocus(tmp
)
211 && (!WFLAGP(tmp
, skip_window_list
)|| tmp
->flags
.internal_window
)) {
212 if (min
->client_win
> tmp
->client_win
)
214 if (tmp
->client_win
> wwin
->client_win
216 || (tmp
->client_win
- wwin
->client_win
) < d
)) {
218 d
= tmp
->client_win
- wwin
->client_win
;
223 if (!closest
||closest
==wwin
)
230 PrevFocusWindow(WScreen
*scr
)
232 WWindow
*tmp
, *wwin
, *closest
, *max
;
235 if (!(wwin
= scr
->focused_window
))
242 if (wWindowCanReceiveFocus(tmp
) &&
243 (!WFLAGP(tmp
, skip_window_list
) || tmp
->flags
.internal_window
)) {
244 if (max
->client_win
< tmp
->client_win
)
246 if (tmp
->client_win
< wwin
->client_win
248 || (wwin
->client_win
- tmp
->client_win
) < d
)) {
250 d
= wwin
->client_win
- tmp
->client_win
;
255 if (!closest
||closest
==wwin
)
264 * Is win2 below win1?
267 isBelow(WWindow
*win1
, WWindow
*win2
)
272 tmp
= win1
->frame
->core
->stacking
->under
;
274 if (tmp
== win2
->frame
->core
)
276 tmp
= tmp
->stacking
->under
;
279 for (i
=win1
->frame
->core
->stacking
->window_level
-1; i
>=0; i
--) {
280 tmp
= win1
->screen_ptr
->stacking_list
[i
];
282 if (tmp
== win2
->frame
->core
)
284 tmp
= tmp
->stacking
->under
;
297 Bool
wFetchName(dpy
, win
, winname
)
302 XTextProperty text_prop
;
306 if (XGetWMName(dpy
, win
, &text_prop
)) {
307 if (text_prop
.value
&& text_prop
.nitems
> 0) {
308 if (text_prop
.encoding
== XA_STRING
) {
309 *winname
= wstrdup((char *)text_prop
.value
);
310 XFree(text_prop
.value
);
312 text_prop
.nitems
= strlen((char *)text_prop
.value
);
313 if (XmbTextPropertyToTextList(dpy
, &text_prop
, &list
, &num
) >=
314 Success
&& num
> 0 && *list
) {
315 XFree(text_prop
.value
);
316 *winname
= wstrdup(*list
);
317 XFreeStringList(list
);
319 *winname
= wstrdup((char *)text_prop
.value
);
320 XFree(text_prop
.value
);
324 /* the title is set, but it was set to none */
325 *winname
= wstrdup("");
329 /* the hint is probably not set */
337 * XGetIconName Wrapper
341 Bool
wGetIconName(dpy
, win
, iconname
)
346 XTextProperty text_prop
;
350 if (XGetWMIconName(dpy
, win
, &text_prop
) != 0 && text_prop
.value
351 && text_prop
.nitems
> 0) {
352 if (text_prop
.encoding
== XA_STRING
)
353 *iconname
= (char *)text_prop
.value
;
355 text_prop
.nitems
= strlen((char *)text_prop
.value
);
356 if (XmbTextPropertyToTextList(dpy
, &text_prop
, &list
, &num
) >=
357 Success
&& num
> 0 && *list
) {
358 XFree(text_prop
.value
);
359 *iconname
= wstrdup(*list
);
360 XFreeStringList(list
);
362 *iconname
= (char *)text_prop
.value
;
376 /* compress all expose events into a single one */
378 if (XCheckMaskEvent(dpy
, ExposureMask
, &event
)) {
379 /* ignore other exposure events for this window */
380 while (XCheckWindowEvent(dpy
, event
.xexpose
.window
, ExposureMask
,
382 /* eat exposes for other windows */
385 event
.xexpose
.count
= 0;
386 XPutBackEvent(dpy
, &event
);
392 SlideWindow(Window win
, int from_x
, int from_y
, int to_x
, int to_y
)
394 time_t time0
= time(NULL
);
395 float dx
, dy
, x
=from_x
, y
=from_y
, sx
, sy
, px
, py
;
398 /* animation parameters */
404 {ICON_SLIDE_DELAY_UF
, ICON_SLIDE_STEPS_UF
, ICON_SLIDE_SLOWDOWN_UF
},
405 {ICON_SLIDE_DELAY_F
, ICON_SLIDE_STEPS_F
, ICON_SLIDE_SLOWDOWN_F
},
406 {ICON_SLIDE_DELAY_M
, ICON_SLIDE_STEPS_M
, ICON_SLIDE_SLOWDOWN_M
},
407 {ICON_SLIDE_DELAY_S
, ICON_SLIDE_STEPS_S
, ICON_SLIDE_SLOWDOWN_S
},
408 {ICON_SLIDE_DELAY_U
, ICON_SLIDE_STEPS_U
, ICON_SLIDE_SLOWDOWN_U
}};
412 dx
= (float)(to_x
-from_x
);
413 dy
= (float)(to_y
-from_y
);
414 sx
= (dx
== 0 ? 0 : fabs(dx
)/dx
);
415 sy
= (dy
== 0 ? 0 : fabs(dy
)/dy
);
417 if (fabs(dx
) > fabs(dy
)) {
422 px
= dx
/ apars
[(int)wPreferences
.icon_slide_speed
].slowdown
;
423 if (px
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
> 0)
424 px
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
425 else if (px
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
< 0)
426 px
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
427 py
= (sx
== 0 ? 0 : px
*dy
/dx
);
429 py
= dy
/ apars
[(int)wPreferences
.icon_slide_speed
].slowdown
;
430 if (py
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
> 0)
431 py
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
432 else if (py
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
< 0)
433 py
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
434 px
= (sy
== 0 ? 0 : py
*dx
/dy
);
437 while (x
!= to_x
|| y
!= to_y
) {
440 if ((px
<0 && (int)x
< to_x
) || (px
>0 && (int)x
> to_x
))
442 if ((py
<0 && (int)y
< to_y
) || (py
>0 && (int)y
> to_y
))
446 px
= px
* (1.0 - 1/(float)apars
[(int)wPreferences
.icon_slide_speed
].slowdown
);
447 if (px
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
> 0)
448 px
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
449 else if (px
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
< 0)
450 px
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
451 py
= (sx
== 0 ? 0 : px
*dy
/dx
);
453 py
= py
* (1.0 - 1/(float)apars
[(int)wPreferences
.icon_slide_speed
].slowdown
);
454 if (py
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
> 0)
455 py
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
456 else if (py
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
< 0)
457 py
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
458 px
= (sy
== 0 ? 0 : py
*dx
/dy
);
461 XMoveWindow(dpy
, win
, (int)x
, (int)y
);
463 if (apars
[(int)wPreferences
.icon_slide_speed
].delay
> 0) {
464 wusleep(apars
[(int)wPreferences
.icon_slide_speed
].delay
*1000L);
466 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
469 XMoveWindow(dpy
, win
, to_x
, to_y
);
472 /* compress expose events */
478 ShrinkString(WMFont
*font
, char *string
, int width
)
486 if (wPreferences
.multi_byte_text
)
487 return wstrdup(string
);
490 w
= WMWidthOfString(font
, string
, p
);
491 text
= wmalloc(strlen(string
)+8);
492 strcpy(text
, string
);
496 pos
= strchr(text
, ' ');
498 pos
= strchr(text
, ':');
503 w1
= WMWidthOfString(font
, text
, p
);
520 width
-= WMWidthOfString(font
, "...", 3);
526 while (p2
>p1
&& p1
!=t
) {
527 w
= WMWidthOfString(font
, &string
[p
-t
], t
);
531 } else if (w
<width
) {
537 strcat(text
, &string
[p
-p1
]);
544 FindImage(char *paths
, char *file
)
548 tmp
= strrchr(file
, ':');
551 path
= wfindfile(paths
, file
);
555 path
= wfindfile(paths
, file
);
563 FlattenStringList(char **list
, int count
)
566 char *flat_string
, *wspace
;
569 for (i
=0; i
<count
; i
++) {
570 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
571 j
+= strlen(list
[i
]);
572 if (strpbrk(list
[i
], " \t"))
577 flat_string
= malloc(j
+count
+1);
583 for (i
=0; i
<count
; i
++) {
584 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
586 strcat(flat_string
, " ");
587 wspace
= strpbrk(list
[i
], " \t");
589 strcat(flat_string
, "\"");
590 strcat(flat_string
, list
[i
]);
592 strcat(flat_string
, "\"");
602 *----------------------------------------------------------------------
604 * Divides a command line into a argv/argc pair.
605 *----------------------------------------------------------------------
620 static DFA mtable
[9][6] = {
621 {{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
622 {{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
623 {{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
624 {{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
625 {{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
626 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
627 {{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
628 {{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
629 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
633 next_token(char *word
, char **next
)
639 t
= ret
= wmalloc(strlen(word
)+1);
653 else if (*ptr
==' ' || *ptr
=='\t')
658 if (mtable
[state
][ctype
].output
) {
662 state
= mtable
[state
][ctype
].nstate
;
664 if (mtable
[state
][0].output
<0) {
686 ParseCommand(char *command
, char ***argv
, int *argc
)
688 WMBag
*bag
= WMCreateBag(4);
694 token
= next_token(line
, &line
);
696 WMPutInBag(bag
, token
);
698 } while (token
!=NULL
&& line
!=NULL
);
700 count
= WMGetBagItemCount(bag
);
701 *argv
= wmalloc(sizeof(char*)*count
);
702 for (j
= 0; j
< count
; j
++) {
703 (*argv
)[j
] = WMGetFromBag(bag
, j
);
718 getselection(WScreen
*scr
)
721 extern char *W_GetTextSelection(); /* in WINGs */
723 tmp
= W_GetTextSelection(scr
->wmscreen
, XA_PRIMARY
);
725 tmp
= W_GetTextSelection(scr
->wmscreen
, XA_CUT_BUFFER0
);
734 puts("getting selection");
736 RequestSelection(dpy
, scr
->no_focus_win
, LastTimestamp
);
737 /* timeout on 1 sec. */
738 id
= WMAddTimerHandler(1000, timeup
, &timeover
);
740 WMNextEvent(dpy
, &event
);
741 if (event
.type
== SelectionNotify
742 && event
.xany
.window
==scr
->no_focus_win
) {
743 WMDeleteTimerHandler(id
);
745 puts("selection ok");
747 return GetSelection(dpy
, scr
->no_focus_win
);
749 WMHandleEvent(&event
);
752 wwarning(_("selection timed-out"));
759 getuserinput(WScreen
*scr
, char *line
, int *ptr
)
766 char tbuffer
[256], pbuffer
[256];
768 title
= _("Program Arguments");
769 prompt
= _("Enter command arguments:");
779 for (; line
[*ptr
]!=0 && state
!=_DONE
; (*ptr
)++) {
782 if (line
[*ptr
]=='(') {
791 if (j
<= 0 && line
[*ptr
]==',') {
795 strncpy(tbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
796 tbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
797 title
= (char*)tbuffer
;
802 } else if (j
<= 0 && line
[*ptr
]==')') {
805 strncpy(tbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
806 tbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
807 title
= (char*)tbuffer
;
811 } else if (line
[*ptr
]=='(') {
813 } else if (line
[*ptr
]==')') {
820 if (line
[*ptr
]==')' && j
==0) {
822 if (*ptr
-begin
> 1) {
823 strncpy(pbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
824 pbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
825 prompt
= (char*)pbuffer
;
828 } else if (line
[*ptr
]=='(')
830 else if (line
[*ptr
]==')')
841 if (!wInputDialog(scr
, title
, prompt
, &ret
))
850 get_dnd_selection(WScreen
*scr
)
852 XTextProperty text_ret
;
858 result
=XGetTextProperty(dpy
, scr
->root_win
, &text_ret
, _XA_DND_SELECTION
);
860 if (result
==0 || text_ret
.value
==NULL
|| text_ret
.encoding
==None
861 || text_ret
.format
==0 || text_ret
.nitems
== 0) {
862 wwarning(_("unable to get dropped data from DND drop"));
866 XTextPropertyToStringList(&text_ret
, &list
, &count
);
868 if (!list
|| count
<1) {
869 XFree(text_ret
.value
);
870 wwarning(_("error getting dropped data from DND drop"));
874 flat_string
= FlattenStringList(list
, count
);
876 wwarning(_("out of memory while getting data from DND drop"));
879 XFreeStringList(list
);
880 XFree(text_ret
.value
);
883 #endif /* OFFIX_DND */
891 * state input new-state output
892 * NORMAL % OPTION <nil>
893 * NORMAL \ ESCAPE <nil>
894 * NORMAL etc. NORMAL <input>
895 * ESCAPE any NORMAL <input>
896 * OPTION s NORMAL <selection buffer>
897 * OPTION w NORMAL <selected window id>
898 * OPTION a NORMAL <input text>
899 * OPTION d NORMAL <OffiX DND selection object>
900 * OPTION W NORMAL <current workspace>
901 * OPTION etc. NORMAL %<input>
903 #define TMPBUFSIZE 64
905 ExpandOptions(WScreen
*scr
, char *cmdline
)
907 int ptr
, optr
, state
, len
, olen
;
909 char *selection
=NULL
;
910 char *user_input
=NULL
;
911 #if defined(OFFIX_DND) || defined(XDND)
912 char *dropped_thing
=NULL
;
914 char tmpbuf
[TMPBUFSIZE
];
917 len
= strlen(cmdline
);
921 wwarning(_("out of memory during expansion of \"%s\""));
925 ptr
= 0; /* input line pointer */
926 optr
= 0; /* output line pointer */
931 switch (cmdline
[ptr
]) {
940 out
[optr
++]=cmdline
[ptr
];
945 switch (cmdline
[ptr
]) {
959 out
[optr
++]=cmdline
[ptr
];
965 switch (cmdline
[ptr
]) {
967 if (scr
->focused_window
968 && scr
->focused_window
->flags
.focused
) {
969 sprintf(tmpbuf
, "0x%x",
970 (unsigned int)scr
->focused_window
->client_win
);
971 slen
= strlen(tmpbuf
);
973 nout
= realloc(out
,olen
);
975 wwarning(_("out of memory during expansion of \"%w\""));
987 sprintf(tmpbuf
, "0x%x",
988 (unsigned int)scr
->current_workspace
+ 1);
989 slen
= strlen(tmpbuf
);
991 nout
= realloc(out
,olen
);
993 wwarning(_("out of memory during expansion of \"%W\""));
1003 user_input
= getuserinput(scr
, cmdline
, &ptr
);
1005 slen
= strlen(user_input
);
1007 nout
= realloc(out
,olen
);
1009 wwarning(_("out of memory during expansion of \"%a\""));
1013 strcat(out
,user_input
);
1016 /* Not an error, but user has Canceled the dialog box.
1017 * This will make the command to not be performed. */
1022 #if defined(OFFIX_DND) || defined(XDND)
1025 if(scr
->xdestring
) {
1026 dropped_thing
= wstrdup(scr
->xdestring
);
1029 if (!dropped_thing
) {
1030 dropped_thing
= get_dnd_selection(scr
);
1032 if (!dropped_thing
) {
1033 scr
->flags
.dnd_data_convertion_status
= 1;
1036 slen
= strlen(dropped_thing
);
1038 nout
= realloc(out
,olen
);
1040 wwarning(_("out of memory during expansion of \"%d\""));
1044 strcat(out
,dropped_thing
);
1047 #endif /* OFFIX_DND */
1051 selection
= getselection(scr
);
1054 wwarning(_("selection not available"));
1057 slen
= strlen(selection
);
1059 nout
= realloc(out
,olen
);
1061 wwarning(_("out of memory during expansion of \"%s\""));
1065 strcat(out
,selection
);
1070 out
[optr
++]=cmdline
[ptr
];
1089 /* We don't care for upper/lower case in comparing the keys; so we
1090 have to define our own comparison function here */
1092 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
1096 str1
= PLGetString(pl1
);
1097 str2
= PLGetString(pl2
);
1099 if (strcasecmp(str1
, str2
)==0)
1106 /* feof doesn't seem to work on pipes */
1108 IsEof(FILE * stream
)
1110 static struct stat stinfo
;
1112 fstat(fileno(stream
), &stinfo
);
1113 return ((S_ISFIFO(stinfo
.st_dev
) && stinfo
.st_size
== 0) ||
1119 ParseWindowName(proplist_t value
, char **winstance
, char **wclass
, char *where
)
1123 *winstance
= *wclass
= NULL
;
1125 if (!PLIsString(value
)) {
1126 wwarning(_("bad window name value in %s state info"), where
);
1130 name
= PLGetString(value
);
1131 if (!name
|| strlen(name
)==0) {
1132 wwarning(_("bad window name value in %s state info"), where
);
1136 UnescapeWM_CLASS(name
, winstance
, wclass
);
1142 keysymToString(KeySym keysym
, unsigned int state
)
1145 char *buf
= wmalloc(20);
1149 kev
.type
= KeyPress
;
1150 kev
.send_event
= False
;
1151 kev
.window
= DefaultRootWindow(dpy
);
1152 kev
.root
= DefaultRootWindow(dpy
);
1153 kev
.same_screen
= True
;
1154 kev
.subwindow
= kev
.root
;
1155 kev
.serial
= 0x12344321;
1156 kev
.time
= CurrentTime
;
1158 kev
.keycode
= XKeysymToKeycode(dpy
, keysym
);
1159 count
= XLookupString(&kev
, buf
, 19, NULL
, NULL
);
1167 GetShortcutString(char *text
)
1169 char *buffer
= NULL
;
1176 tmp
= text
= wstrdup(text
);
1179 while ((k
= strchr(text
, '+'))!=NULL
) {
1183 mod
= wXModifierFromKey(text
);
1185 return wstrdup("bug");
1190 if (strcasecmp(text
, "Meta")==0) {
1191 buffer
= wstrappend(buffer
, "M+");
1192 } else if (strcasecmp(text
, "Alt")==0) {
1193 buffer
= wstrappend(buffer
, "A+");
1194 } else if (strcasecmp(text
, "Shift")==0) {
1195 buffer
= wstrappend(buffer
, "Sh+");
1196 } else if (strcasecmp(text
, "Mod1")==0) {
1197 buffer
= wstrappend(buffer
, "M1+");
1198 } else if (strcasecmp(text
, "Mod2")==0) {
1199 buffer
= wstrappend(buffer
, "M2+");
1200 } else if (strcasecmp(text
, "Mod3")==0) {
1201 buffer
= wstrappend(buffer
, "M3+");
1202 } else if (strcasecmp(text
, "Mod4")==0) {
1203 buffer
= wstrappend(buffer
, "M4+");
1204 } else if (strcasecmp(text
, "Mod5")==0) {
1205 buffer
= wstrappend(buffer
, "M5+");
1206 } else if (strcasecmp(text
, "Control")==0) {
1209 buffer
= wstrappend(buffer
, text
);
1215 buffer
= wstrappend(buffer
, "^");
1217 buffer
= wstrappend(buffer
, text
);
1220 /* ksym = XStringToKeysym(text);
1221 tmp = keysymToString(ksym, modmask);
1223 buffer = wstrappend(buffer, tmp);
1232 EscapeWM_CLASS(char *name
, char *class)
1235 char *ename
= NULL
, *eclass
= NULL
;
1238 if (!name
&& !class)
1243 ename
= wmalloc(l
*2);
1245 for (i
=0; i
<l
; i
++) {
1246 if (name
[i
]=='\\') {
1248 } else if (name
[i
]=='.') {
1251 ename
[j
++] = name
[i
];
1257 eclass
= wmalloc(l
*2);
1259 for (i
=0; i
<l
; i
++) {
1260 if (class[i
]=='\\') {
1262 } else if (class[i
]=='.') {
1265 eclass
[j
++] = class[i
];
1270 if (ename
&& eclass
) {
1271 ret
= wmalloc(strlen(ename
)+strlen(eclass
)+4);
1272 sprintf(ret
, "%s.%s", ename
, eclass
);
1276 ret
= wstrdup(ename
);
1279 ret
= wstrdup(eclass
);
1288 UnescapeWM_CLASS(char *str
, char **name
, char **class)
1296 *class = wmalloc(j
);
1299 /* separate string in 2 parts */
1302 for (i
= 0; i
< j
; i
++) {
1306 } else if (str
[i
]=='.') {
1315 /* unescape strings */
1318 for (i
= 0; i
< dot
; i
++) {
1323 (*name
)[k
++] = str
[i
];
1326 (*name
)[k
++] = str
[i
];
1334 for (i
= dot
+1; i
<j
; i
++) {
1339 (*class)[k
++] = str
[i
];
1360 SendHelperMessage(WScreen
*scr
, char type
, int workspace
, char *msg
)
1362 unsigned char *buffer
;
1367 if (!scr
->flags
.backimage_helper_launched
) {
1371 len
= (msg
? strlen(msg
) : 0) + (workspace
>=0 ? 4 : 0) + 1 ;
1372 buffer
= wmalloc(len
+5);
1373 sprintf(buf
, "%4i", len
);
1374 memcpy(buffer
, buf
, 4);
1377 if (workspace
>= 0) {
1378 sprintf(buf
, "%4i", workspace
);
1379 memcpy(&buffer
[i
], buf
, 4);
1384 strcpy(&buffer
[i
], msg
);
1386 if (write(scr
->helper_fd
, buffer
, len
+4) < 0) {
1387 wsyserror(_("could not send message to background image helper"));
1401 shellCommandHandler(pid_t pid
, unsigned char status
, _tuple
*data
)
1403 if (status
== 127) {
1406 buffer
= wstrappend(_("Could not execute command: "), data
->command
);
1408 wMessageDialog(data
->scr
, _("Error"), buffer
, _("OK"), NULL
, NULL
);
1410 } else if (status
!= 127) {
1412 printf("%s: %i\n", data->command, status);
1416 free(data
->command
);
1422 ExecuteShellCommand(WScreen
*scr
, char *command
)
1424 static char *shell
= NULL
;
1428 * This have a problem: if the shell is tcsh (not sure about others)
1429 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
1430 * will block and the command will not be executed.
1432 shell = getenv("SHELL");
1443 SetupEnvironment(scr
);
1448 execl(shell
, shell
, "-c", command
, NULL
);
1449 wsyserror("could not execute %s -c %s", shell
, command
);
1451 } else if (pid
< 0) {
1452 wsyserror("cannot fork a new process");
1454 _tuple
*data
= wmalloc(sizeof(_tuple
));
1457 data
->command
= wstrdup(command
);
1459 wAddDeathHandler(pid
, (WDeathHandler
*)shellCommandHandler
, data
);
1467 void dbprintf(char *format
, ...)
1471 va_start(args
, format
);
1472 vprintf(format
, args
);
1479 void dbputs(char *text
)