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
= strchr(tmp
+1, ' ');
162 buf
= strrchr(tmp
, '/');
164 *buf
= 0; /* trunc filename */
165 putdef(line
, " -I", tmp
);
171 /* this should be done just once, but it works this way */
172 strcpy(buffer
, DEF_CONFIG_PATHS
);
173 buf
= strtok(buffer
, ":");
176 char fullpath
[MAXLINE
];
179 strcpy(fullpath
, buf
);
181 char * wgethomedir();
182 /* home is statically allocated. Don't free it! */
183 char *home
= wgethomedir();
185 strcpy(fullpath
, home
);
186 strcat(fullpath
, &(buf
[1]));
189 putdef(line
, " -I", fullpath
);
191 } while ((buf
= strtok(NULL
, ":"))!=NULL
);
207 * Is win2 below win1?
210 isBelow(WWindow
*win1
, WWindow
*win2
)
215 tmp
= win1
->frame
->core
->stacking
->under
;
217 if (tmp
== win2
->frame
->core
)
219 tmp
= tmp
->stacking
->under
;
222 for (i
=win1
->frame
->core
->stacking
->window_level
-1; i
>=0; i
--) {
223 tmp
= win1
->screen_ptr
->stacking_list
[i
];
225 if (tmp
== win2
->frame
->core
)
227 tmp
= tmp
->stacking
->under
;
240 Bool
wFetchName(dpy
, win
, winname
)
245 XTextProperty text_prop
;
249 if (XGetWMName(dpy
, win
, &text_prop
)) {
250 if (text_prop
.value
&& text_prop
.nitems
> 0) {
251 if (text_prop
.encoding
== XA_STRING
) {
252 *winname
= wstrdup((char *)text_prop
.value
);
253 XFree(text_prop
.value
);
255 text_prop
.nitems
= strlen((char *)text_prop
.value
);
256 if (XmbTextPropertyToTextList(dpy
, &text_prop
, &list
, &num
) >=
257 Success
&& num
> 0 && *list
) {
258 XFree(text_prop
.value
);
259 *winname
= wstrdup(*list
);
260 XFreeStringList(list
);
262 *winname
= wstrdup((char *)text_prop
.value
);
263 XFree(text_prop
.value
);
267 /* the title is set, but it was set to none */
268 *winname
= wstrdup("");
272 /* the hint is probably not set */
280 * XGetIconName Wrapper
284 Bool
wGetIconName(dpy
, win
, iconname
)
289 XTextProperty text_prop
;
293 if (XGetWMIconName(dpy
, win
, &text_prop
) != 0 && text_prop
.value
294 && text_prop
.nitems
> 0) {
295 if (text_prop
.encoding
== XA_STRING
)
296 *iconname
= (char *)text_prop
.value
;
298 text_prop
.nitems
= strlen((char *)text_prop
.value
);
299 if (XmbTextPropertyToTextList(dpy
, &text_prop
, &list
, &num
) >=
300 Success
&& num
> 0 && *list
) {
301 XFree(text_prop
.value
);
302 *iconname
= wstrdup(*list
);
303 XFreeStringList(list
);
305 *iconname
= (char *)text_prop
.value
;
319 /* compress all expose events into a single one */
321 if (XCheckMaskEvent(dpy
, ExposureMask
, &event
)) {
322 /* ignore other exposure events for this window */
323 while (XCheckWindowEvent(dpy
, event
.xexpose
.window
, ExposureMask
,
325 /* eat exposes for other windows */
328 event
.xexpose
.count
= 0;
329 XPutBackEvent(dpy
, &event
);
335 SlideWindow(Window win
, int from_x
, int from_y
, int to_x
, int to_y
)
337 time_t time0
= time(NULL
);
338 float dx
, dy
, x
=from_x
, y
=from_y
, sx
, sy
, px
, py
;
341 /* animation parameters */
347 {ICON_SLIDE_DELAY_UF
, ICON_SLIDE_STEPS_UF
, ICON_SLIDE_SLOWDOWN_UF
},
348 {ICON_SLIDE_DELAY_F
, ICON_SLIDE_STEPS_F
, ICON_SLIDE_SLOWDOWN_F
},
349 {ICON_SLIDE_DELAY_M
, ICON_SLIDE_STEPS_M
, ICON_SLIDE_SLOWDOWN_M
},
350 {ICON_SLIDE_DELAY_S
, ICON_SLIDE_STEPS_S
, ICON_SLIDE_SLOWDOWN_S
},
351 {ICON_SLIDE_DELAY_U
, ICON_SLIDE_STEPS_U
, ICON_SLIDE_SLOWDOWN_U
}};
355 dx
= (float)(to_x
-from_x
);
356 dy
= (float)(to_y
-from_y
);
357 sx
= (dx
== 0 ? 0 : fabs(dx
)/dx
);
358 sy
= (dy
== 0 ? 0 : fabs(dy
)/dy
);
360 if (fabs(dx
) > fabs(dy
)) {
365 px
= dx
/ apars
[(int)wPreferences
.icon_slide_speed
].slowdown
;
366 if (px
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
> 0)
367 px
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
368 else if (px
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
< 0)
369 px
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
370 py
= (sx
== 0 ? 0 : px
*dy
/dx
);
372 py
= dy
/ apars
[(int)wPreferences
.icon_slide_speed
].slowdown
;
373 if (py
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
> 0)
374 py
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
375 else if (py
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
< 0)
376 py
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
377 px
= (sy
== 0 ? 0 : py
*dx
/dy
);
380 while (x
!= to_x
|| y
!= to_y
) {
383 if ((px
<0 && (int)x
< to_x
) || (px
>0 && (int)x
> to_x
))
385 if ((py
<0 && (int)y
< to_y
) || (py
>0 && (int)y
> to_y
))
389 px
= px
* (1.0 - 1/(float)apars
[(int)wPreferences
.icon_slide_speed
].slowdown
);
390 if (px
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
> 0)
391 px
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
392 else if (px
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
< 0)
393 px
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
394 py
= (sx
== 0 ? 0 : px
*dy
/dx
);
396 py
= py
* (1.0 - 1/(float)apars
[(int)wPreferences
.icon_slide_speed
].slowdown
);
397 if (py
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
> 0)
398 py
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
399 else if (py
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
< 0)
400 py
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
401 px
= (sy
== 0 ? 0 : py
*dx
/dy
);
404 XMoveWindow(dpy
, win
, (int)x
, (int)y
);
406 if (apars
[(int)wPreferences
.icon_slide_speed
].delay
> 0) {
407 wusleep(apars
[(int)wPreferences
.icon_slide_speed
].delay
*1000L);
409 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
412 XMoveWindow(dpy
, win
, to_x
, to_y
);
415 /* compress expose events */
421 ShrinkString(WMFont
*font
, char *string
, int width
)
429 if (wPreferences
.multi_byte_text
)
430 return wstrdup(string
);
433 w
= WMWidthOfString(font
, string
, p
);
434 text
= wmalloc(strlen(string
)+8);
435 strcpy(text
, string
);
439 pos
= strchr(text
, ' ');
441 pos
= strchr(text
, ':');
446 w1
= WMWidthOfString(font
, text
, p
);
463 width
-= WMWidthOfString(font
, "...", 3);
469 while (p2
>p1
&& p1
!=t
) {
470 w
= WMWidthOfString(font
, &string
[p
-t
], t
);
474 } else if (w
<width
) {
480 strcat(text
, &string
[p
-p1
]);
487 FindImage(char *paths
, char *file
)
491 tmp
= strrchr(file
, ':');
494 path
= wfindfile(paths
, file
);
498 path
= wfindfile(paths
, file
);
506 FlattenStringList(char **list
, int count
)
509 char *flat_string
, *wspace
;
512 for (i
=0; i
<count
; i
++) {
513 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
514 j
+= strlen(list
[i
]);
515 if (strpbrk(list
[i
], " \t"))
520 flat_string
= malloc(j
+count
+1);
526 for (i
=0; i
<count
; i
++) {
527 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
529 strcat(flat_string
, " ");
530 wspace
= strpbrk(list
[i
], " \t");
532 strcat(flat_string
, "\"");
533 strcat(flat_string
, list
[i
]);
535 strcat(flat_string
, "\"");
545 *----------------------------------------------------------------------
547 * Divides a command line into a argv/argc pair.
548 *----------------------------------------------------------------------
563 static DFA mtable
[9][6] = {
564 {{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
565 {{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
566 {{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
567 {{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
568 {{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
569 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
570 {{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
571 {{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
572 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
576 next_token(char *word
, char **next
)
582 t
= ret
= wmalloc(strlen(word
)+1);
596 else if (*ptr
==' ' || *ptr
=='\t')
601 if (mtable
[state
][ctype
].output
) {
605 state
= mtable
[state
][ctype
].nstate
;
607 if (mtable
[state
][0].output
<0) {
628 /* separate a string in tokens, taking " and ' into account */
630 TokenizeString(char *command
, char ***argv
, int *argc
)
638 token
= next_token(line
, &line
);
641 *argv
= wmalloc(sizeof(char**));
643 *argv
= wrealloc(*argv
, (count
+1)*sizeof(char**));
644 (*argv
)[count
++] = token
;
646 } while (token
!=NULL
&& line
!=NULL
);
653 timeoutHandler(void *data
)
660 getTextSelection(WScreen
*screen
, Atom selection
)
694 data
= XFetchBuffer(dpy
, &size
, buffer
);
701 unsigned long len
, bytes
;
705 static Atom clipboard
= 0;
708 clipboard
= XInternAtom(dpy
, "CLIPBOARD", False
);
710 XDeleteProperty(dpy
, screen
->info_window
, clipboard
);
712 XConvertSelection(dpy
, selection
, XA_STRING
,
713 clipboard
, screen
->info_window
,
716 timer
= WMAddTimerHandler(1000, timeoutHandler
, &timeout
);
718 while (!XCheckTypedWindowEvent(dpy
, screen
->info_window
,
719 SelectionNotify
, &ev
) && !timeout
);
722 WMDeleteTimerHandler(timer
);
724 wwarning("selection retrieval timed out");
728 /* nobody owns the selection or the current owner has
729 * nothing to do with what we need */
730 if (ev
.xselection
.property
== None
) {
734 if (XGetWindowProperty(dpy
, screen
->info_window
,
736 False
, XA_STRING
, &rtype
, &bits
, &len
,
737 &bytes
, (unsigned char**)&data
)!=Success
) {
740 if (rtype
!=XA_STRING
|| bits
!=8) {
741 wwarning("invalid data in text selection");
751 getselection(WScreen
*scr
)
755 tmp
= getTextSelection(scr
, XA_PRIMARY
);
757 tmp
= getTextSelection(scr
, XA_CUT_BUFFER0
);
763 getuserinput(WScreen
*scr
, char *line
, int *ptr
)
770 char tbuffer
[256], pbuffer
[256];
772 title
= _("Program Arguments");
773 prompt
= _("Enter command arguments:");
783 for (; line
[*ptr
]!=0 && state
!=_DONE
; (*ptr
)++) {
786 if (line
[*ptr
]=='(') {
795 if (j
<= 0 && line
[*ptr
]==',') {
799 strncpy(tbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
800 tbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
801 title
= (char*)tbuffer
;
806 } else if (j
<= 0 && line
[*ptr
]==')') {
809 strncpy(tbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
810 tbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
811 title
= (char*)tbuffer
;
815 } else if (line
[*ptr
]=='(') {
817 } else if (line
[*ptr
]==')') {
824 if (line
[*ptr
]==')' && j
==0) {
826 if (*ptr
-begin
> 1) {
827 strncpy(pbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
828 pbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
829 prompt
= (char*)pbuffer
;
832 } else if (line
[*ptr
]=='(')
834 else if (line
[*ptr
]==')')
845 if (!wInputDialog(scr
, title
, prompt
, &ret
))
854 get_dnd_selection(WScreen
*scr
)
856 XTextProperty text_ret
;
862 result
=XGetTextProperty(dpy
, scr
->root_win
, &text_ret
, _XA_DND_SELECTION
);
864 if (result
==0 || text_ret
.value
==NULL
|| text_ret
.encoding
==None
865 || text_ret
.format
==0 || text_ret
.nitems
== 0) {
866 wwarning(_("unable to get dropped data from DND drop"));
870 XTextPropertyToStringList(&text_ret
, &list
, &count
);
872 if (!list
|| count
<1) {
873 XFree(text_ret
.value
);
874 wwarning(_("error getting dropped data from DND drop"));
878 flat_string
= FlattenStringList(list
, count
);
880 wwarning(_("out of memory while getting data from DND drop"));
883 XFreeStringList(list
);
884 XFree(text_ret
.value
);
887 #endif /* OFFIX_DND */
895 * state input new-state output
896 * NORMAL % OPTION <nil>
897 * NORMAL \ ESCAPE <nil>
898 * NORMAL etc. NORMAL <input>
899 * ESCAPE any NORMAL <input>
900 * OPTION s NORMAL <selection buffer>
901 * OPTION w NORMAL <selected window id>
902 * OPTION a NORMAL <input text>
903 * OPTION d NORMAL <OffiX DND selection object>
904 * OPTION W NORMAL <current workspace>
905 * OPTION etc. NORMAL %<input>
907 #define TMPBUFSIZE 64
909 ExpandOptions(WScreen
*scr
, char *cmdline
)
911 int ptr
, optr
, state
, len
, olen
;
913 char *selection
=NULL
;
914 char *user_input
=NULL
;
915 #if defined(OFFIX_DND) || defined(XDND)
916 char *dropped_thing
=NULL
;
918 char tmpbuf
[TMPBUFSIZE
];
921 len
= strlen(cmdline
);
925 wwarning(_("out of memory during expansion of \"%s\""));
929 ptr
= 0; /* input line pointer */
930 optr
= 0; /* output line pointer */
935 switch (cmdline
[ptr
]) {
944 out
[optr
++]=cmdline
[ptr
];
949 switch (cmdline
[ptr
]) {
963 out
[optr
++]=cmdline
[ptr
];
969 switch (cmdline
[ptr
]) {
971 if (scr
->focused_window
972 && scr
->focused_window
->flags
.focused
) {
973 sprintf(tmpbuf
, "0x%x",
974 (unsigned int)scr
->focused_window
->client_win
);
975 slen
= strlen(tmpbuf
);
977 nout
= realloc(out
,olen
);
979 wwarning(_("out of memory during expansion of \"%w\""));
991 sprintf(tmpbuf
, "0x%x",
992 (unsigned int)scr
->current_workspace
+ 1);
993 slen
= strlen(tmpbuf
);
995 nout
= realloc(out
,olen
);
997 wwarning(_("out of memory during expansion of \"%W\""));
1007 user_input
= getuserinput(scr
, cmdline
, &ptr
);
1009 slen
= strlen(user_input
);
1011 nout
= realloc(out
,olen
);
1013 wwarning(_("out of memory during expansion of \"%a\""));
1017 strcat(out
,user_input
);
1020 /* Not an error, but user has Canceled the dialog box.
1021 * This will make the command to not be performed. */
1026 #if defined(OFFIX_DND) || defined(XDND)
1029 if(scr
->xdestring
) {
1030 dropped_thing
= wstrdup(scr
->xdestring
);
1033 if (!dropped_thing
) {
1034 dropped_thing
= get_dnd_selection(scr
);
1036 if (!dropped_thing
) {
1037 scr
->flags
.dnd_data_convertion_status
= 1;
1040 slen
= strlen(dropped_thing
);
1042 nout
= realloc(out
,olen
);
1044 wwarning(_("out of memory during expansion of \"%d\""));
1048 strcat(out
,dropped_thing
);
1051 #endif /* OFFIX_DND */
1055 selection
= getselection(scr
);
1058 wwarning(_("selection not available"));
1061 slen
= strlen(selection
);
1063 nout
= realloc(out
,olen
);
1065 wwarning(_("out of memory during expansion of \"%s\""));
1069 strcat(out
,selection
);
1075 out
[optr
++]=cmdline
[ptr
];
1094 /* We don't care for upper/lower case in comparing the keys; so we
1095 have to define our own comparison function here */
1097 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
1101 str1
= PLGetString(pl1
);
1102 str2
= PLGetString(pl2
);
1104 if (strcasecmp(str1
, str2
)==0)
1111 /* feof doesn't seem to work on pipes */
1113 IsEof(FILE * stream
)
1115 static struct stat stinfo
;
1117 fstat(fileno(stream
), &stinfo
);
1118 return ((S_ISFIFO(stinfo
.st_dev
) && stinfo
.st_size
== 0) ||
1124 ParseWindowName(proplist_t value
, char **winstance
, char **wclass
, char *where
)
1128 *winstance
= *wclass
= NULL
;
1130 if (!PLIsString(value
)) {
1131 wwarning(_("bad window name value in %s state info"), where
);
1135 name
= PLGetString(value
);
1136 if (!name
|| strlen(name
)==0) {
1137 wwarning(_("bad window name value in %s state info"), where
);
1141 UnescapeWM_CLASS(name
, winstance
, wclass
);
1147 keysymToString(KeySym keysym
, unsigned int state
)
1150 char *buf
= wmalloc(20);
1154 kev
.type
= KeyPress
;
1155 kev
.send_event
= False
;
1156 kev
.window
= DefaultRootWindow(dpy
);
1157 kev
.root
= DefaultRootWindow(dpy
);
1158 kev
.same_screen
= True
;
1159 kev
.subwindow
= kev
.root
;
1160 kev
.serial
= 0x12344321;
1161 kev
.time
= CurrentTime
;
1163 kev
.keycode
= XKeysymToKeycode(dpy
, keysym
);
1164 count
= XLookupString(&kev
, buf
, 19, NULL
, NULL
);
1172 appendrealloc(char *a
, char *b
)
1177 char *c
= wstrappend(a
, b
);
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
= appendrealloc(buffer
, "M+");
1210 } else if (strcasecmp(text
, "Alt")==0) {
1211 buffer
= appendrealloc(buffer
, "A+");
1212 } else if (strcasecmp(text
, "Shift")==0) {
1213 buffer
= appendrealloc(buffer
, "Sh+");
1214 } else if (strcasecmp(text
, "Mod1")==0) {
1215 buffer
= appendrealloc(buffer
, "M1+");
1216 } else if (strcasecmp(text
, "Mod2")==0) {
1217 buffer
= appendrealloc(buffer
, "M2+");
1218 } else if (strcasecmp(text
, "Mod3")==0) {
1219 buffer
= appendrealloc(buffer
, "M3+");
1220 } else if (strcasecmp(text
, "Mod4")==0) {
1221 buffer
= appendrealloc(buffer
, "M4+");
1222 } else if (strcasecmp(text
, "Mod5")==0) {
1223 buffer
= appendrealloc(buffer
, "M5+");
1224 } else if (strcasecmp(text
, "Control")==0) {
1227 buffer
= appendrealloc(buffer
, text
);
1233 buffer
= appendrealloc(buffer
, "^");
1235 buffer
= appendrealloc(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"));