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 NextToFocusAfter(WWindow
*wwin
)
209 WWindow
*tmp
= wwin
->prev
;
212 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
219 /* start over from the beginning of the list */
223 while (tmp
&& tmp
!= wwin
) {
224 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
235 NextToFocusBefore(WWindow
*wwin
)
237 WWindow
*tmp
= wwin
->next
;
240 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
246 /* start over from the beginning of the list */
251 while (tmp
&& tmp
!= wwin
) {
252 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
265 * Is win2 below win1?
268 isBelow(WWindow
*win1
, WWindow
*win2
)
273 tmp
= win1
->frame
->core
->stacking
->under
;
275 if (tmp
== win2
->frame
->core
)
277 tmp
= tmp
->stacking
->under
;
280 for (i
=win1
->frame
->core
->stacking
->window_level
-1; i
>=0; i
--) {
281 tmp
= win1
->screen_ptr
->stacking_list
[i
];
283 if (tmp
== win2
->frame
->core
)
285 tmp
= tmp
->stacking
->under
;
298 Bool
wFetchName(dpy
, win
, winname
)
303 XTextProperty text_prop
;
307 if (XGetWMName(dpy
, win
, &text_prop
)) {
308 if (text_prop
.value
&& text_prop
.nitems
> 0) {
309 if (text_prop
.encoding
== XA_STRING
) {
310 *winname
= wstrdup((char *)text_prop
.value
);
311 XFree(text_prop
.value
);
313 text_prop
.nitems
= strlen((char *)text_prop
.value
);
314 if (XmbTextPropertyToTextList(dpy
, &text_prop
, &list
, &num
) >=
315 Success
&& num
> 0 && *list
) {
316 XFree(text_prop
.value
);
317 *winname
= wstrdup(*list
);
318 XFreeStringList(list
);
320 *winname
= wstrdup((char *)text_prop
.value
);
321 XFree(text_prop
.value
);
325 /* the title is set, but it was set to none */
326 *winname
= wstrdup("");
330 /* the hint is probably not set */
338 * XGetIconName Wrapper
342 Bool
wGetIconName(dpy
, win
, iconname
)
347 XTextProperty text_prop
;
351 if (XGetWMIconName(dpy
, win
, &text_prop
) != 0 && text_prop
.value
352 && text_prop
.nitems
> 0) {
353 if (text_prop
.encoding
== XA_STRING
)
354 *iconname
= (char *)text_prop
.value
;
356 text_prop
.nitems
= strlen((char *)text_prop
.value
);
357 if (XmbTextPropertyToTextList(dpy
, &text_prop
, &list
, &num
) >=
358 Success
&& num
> 0 && *list
) {
359 XFree(text_prop
.value
);
360 *iconname
= wstrdup(*list
);
361 XFreeStringList(list
);
363 *iconname
= (char *)text_prop
.value
;
377 /* compress all expose events into a single one */
379 if (XCheckMaskEvent(dpy
, ExposureMask
, &event
)) {
380 /* ignore other exposure events for this window */
381 while (XCheckWindowEvent(dpy
, event
.xexpose
.window
, ExposureMask
,
383 /* eat exposes for other windows */
386 event
.xexpose
.count
= 0;
387 XPutBackEvent(dpy
, &event
);
393 SlideWindow(Window win
, int from_x
, int from_y
, int to_x
, int to_y
)
395 time_t time0
= time(NULL
);
396 float dx
, dy
, x
=from_x
, y
=from_y
, sx
, sy
, px
, py
;
399 /* animation parameters */
405 {ICON_SLIDE_DELAY_UF
, ICON_SLIDE_STEPS_UF
, ICON_SLIDE_SLOWDOWN_UF
},
406 {ICON_SLIDE_DELAY_F
, ICON_SLIDE_STEPS_F
, ICON_SLIDE_SLOWDOWN_F
},
407 {ICON_SLIDE_DELAY_M
, ICON_SLIDE_STEPS_M
, ICON_SLIDE_SLOWDOWN_M
},
408 {ICON_SLIDE_DELAY_S
, ICON_SLIDE_STEPS_S
, ICON_SLIDE_SLOWDOWN_S
},
409 {ICON_SLIDE_DELAY_U
, ICON_SLIDE_STEPS_U
, ICON_SLIDE_SLOWDOWN_U
}};
413 dx
= (float)(to_x
-from_x
);
414 dy
= (float)(to_y
-from_y
);
415 sx
= (dx
== 0 ? 0 : fabs(dx
)/dx
);
416 sy
= (dy
== 0 ? 0 : fabs(dy
)/dy
);
418 if (fabs(dx
) > fabs(dy
)) {
423 px
= dx
/ apars
[(int)wPreferences
.icon_slide_speed
].slowdown
;
424 if (px
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
> 0)
425 px
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
426 else if (px
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
< 0)
427 px
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
428 py
= (sx
== 0 ? 0 : px
*dy
/dx
);
430 py
= dy
/ apars
[(int)wPreferences
.icon_slide_speed
].slowdown
;
431 if (py
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
> 0)
432 py
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
433 else if (py
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
< 0)
434 py
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
435 px
= (sy
== 0 ? 0 : py
*dx
/dy
);
438 while (x
!= to_x
|| y
!= to_y
) {
441 if ((px
<0 && (int)x
< to_x
) || (px
>0 && (int)x
> to_x
))
443 if ((py
<0 && (int)y
< to_y
) || (py
>0 && (int)y
> to_y
))
447 px
= px
* (1.0 - 1/(float)apars
[(int)wPreferences
.icon_slide_speed
].slowdown
);
448 if (px
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
> 0)
449 px
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
450 else if (px
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& px
< 0)
451 px
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
452 py
= (sx
== 0 ? 0 : px
*dy
/dx
);
454 py
= py
* (1.0 - 1/(float)apars
[(int)wPreferences
.icon_slide_speed
].slowdown
);
455 if (py
< apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
> 0)
456 py
= apars
[(int)wPreferences
.icon_slide_speed
].steps
;
457 else if (py
> -apars
[(int)wPreferences
.icon_slide_speed
].steps
&& py
< 0)
458 py
= -apars
[(int)wPreferences
.icon_slide_speed
].steps
;
459 px
= (sy
== 0 ? 0 : py
*dx
/dy
);
462 XMoveWindow(dpy
, win
, (int)x
, (int)y
);
464 if (apars
[(int)wPreferences
.icon_slide_speed
].delay
> 0) {
465 wusleep(apars
[(int)wPreferences
.icon_slide_speed
].delay
*1000L);
467 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
470 XMoveWindow(dpy
, win
, to_x
, to_y
);
473 /* compress expose events */
479 ShrinkString(WMFont
*font
, char *string
, int width
)
487 if (wPreferences
.multi_byte_text
)
488 return wstrdup(string
);
491 w
= WMWidthOfString(font
, string
, p
);
492 text
= wmalloc(strlen(string
)+8);
493 strcpy(text
, string
);
497 pos
= strchr(text
, ' ');
499 pos
= strchr(text
, ':');
504 w1
= WMWidthOfString(font
, text
, p
);
521 width
-= WMWidthOfString(font
, "...", 3);
527 while (p2
>p1
&& p1
!=t
) {
528 w
= WMWidthOfString(font
, &string
[p
-t
], t
);
532 } else if (w
<width
) {
538 strcat(text
, &string
[p
-p1
]);
545 FindImage(char *paths
, char *file
)
549 tmp
= strrchr(file
, ':');
552 path
= wfindfile(paths
, file
);
556 path
= wfindfile(paths
, file
);
564 FlattenStringList(char **list
, int count
)
567 char *flat_string
, *wspace
;
570 for (i
=0; i
<count
; i
++) {
571 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
572 j
+= strlen(list
[i
]);
573 if (strpbrk(list
[i
], " \t"))
578 flat_string
= malloc(j
+count
+1);
584 for (i
=0; i
<count
; i
++) {
585 if (list
[i
]!=NULL
&& list
[i
][0]!=0) {
587 strcat(flat_string
, " ");
588 wspace
= strpbrk(list
[i
], " \t");
590 strcat(flat_string
, "\"");
591 strcat(flat_string
, list
[i
]);
593 strcat(flat_string
, "\"");
603 *----------------------------------------------------------------------
605 * Divides a command line into a argv/argc pair.
606 *----------------------------------------------------------------------
621 static DFA mtable
[9][6] = {
622 {{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
623 {{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
624 {{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
625 {{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
626 {{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
627 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
628 {{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
629 {{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
630 {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
634 next_token(char *word
, char **next
)
640 t
= ret
= wmalloc(strlen(word
)+1);
654 else if (*ptr
==' ' || *ptr
=='\t')
659 if (mtable
[state
][ctype
].output
) {
663 state
= mtable
[state
][ctype
].nstate
;
665 if (mtable
[state
][0].output
<0) {
687 ParseCommand(char *command
, char ***argv
, int *argc
)
689 WMBag
*bag
= WMCreateBag(4);
695 token
= next_token(line
, &line
);
697 WMPutInBag(bag
, token
);
699 } while (token
!=NULL
&& line
!=NULL
);
701 count
= WMGetBagItemCount(bag
);
702 *argv
= wmalloc(sizeof(char*)*count
);
703 for (j
= 0; j
< count
; j
++) {
704 (*argv
)[j
] = WMGetFromBag(bag
, j
);
719 getselection(WScreen
*scr
)
722 extern char *W_GetTextSelection(); /* in WINGs */
724 tmp
= W_GetTextSelection(scr
->wmscreen
, XA_PRIMARY
);
726 tmp
= W_GetTextSelection(scr
->wmscreen
, XA_CUT_BUFFER0
);
735 puts("getting selection");
737 RequestSelection(dpy
, scr
->no_focus_win
, LastTimestamp
);
738 /* timeout on 1 sec. */
739 id
= WMAddTimerHandler(1000, timeup
, &timeover
);
741 WMNextEvent(dpy
, &event
);
742 if (event
.type
== SelectionNotify
743 && event
.xany
.window
==scr
->no_focus_win
) {
744 WMDeleteTimerHandler(id
);
746 puts("selection ok");
748 return GetSelection(dpy
, scr
->no_focus_win
);
750 WMHandleEvent(&event
);
753 wwarning(_("selection timed-out"));
760 getuserinput(WScreen
*scr
, char *line
, int *ptr
)
767 char tbuffer
[256], pbuffer
[256];
769 title
= _("Program Arguments");
770 prompt
= _("Enter command arguments:");
780 for (; line
[*ptr
]!=0 && state
!=_DONE
; (*ptr
)++) {
783 if (line
[*ptr
]=='(') {
792 if (j
<= 0 && line
[*ptr
]==',') {
796 strncpy(tbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
797 tbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
798 title
= (char*)tbuffer
;
803 } else if (j
<= 0 && line
[*ptr
]==')') {
806 strncpy(tbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
807 tbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
808 title
= (char*)tbuffer
;
812 } else if (line
[*ptr
]=='(') {
814 } else if (line
[*ptr
]==')') {
821 if (line
[*ptr
]==')' && j
==0) {
823 if (*ptr
-begin
> 1) {
824 strncpy(pbuffer
, &line
[begin
], WMIN(*ptr
-begin
, 255));
825 pbuffer
[WMIN(*ptr
-begin
, 255)] = 0;
826 prompt
= (char*)pbuffer
;
829 } else if (line
[*ptr
]=='(')
831 else if (line
[*ptr
]==')')
842 if (!wInputDialog(scr
, title
, prompt
, &ret
))
851 get_dnd_selection(WScreen
*scr
)
853 XTextProperty text_ret
;
859 result
=XGetTextProperty(dpy
, scr
->root_win
, &text_ret
, _XA_DND_SELECTION
);
861 if (result
==0 || text_ret
.value
==NULL
|| text_ret
.encoding
==None
862 || text_ret
.format
==0 || text_ret
.nitems
== 0) {
863 wwarning(_("unable to get dropped data from DND drop"));
867 XTextPropertyToStringList(&text_ret
, &list
, &count
);
869 if (!list
|| count
<1) {
870 XFree(text_ret
.value
);
871 wwarning(_("error getting dropped data from DND drop"));
875 flat_string
= FlattenStringList(list
, count
);
877 wwarning(_("out of memory while getting data from DND drop"));
880 XFreeStringList(list
);
881 XFree(text_ret
.value
);
884 #endif /* OFFIX_DND */
892 * state input new-state output
893 * NORMAL % OPTION <nil>
894 * NORMAL \ ESCAPE <nil>
895 * NORMAL etc. NORMAL <input>
896 * ESCAPE any NORMAL <input>
897 * OPTION s NORMAL <selection buffer>
898 * OPTION w NORMAL <selected window id>
899 * OPTION a NORMAL <input text>
900 * OPTION d NORMAL <OffiX DND selection object>
901 * OPTION W NORMAL <current workspace>
902 * OPTION etc. NORMAL %<input>
904 #define TMPBUFSIZE 64
906 ExpandOptions(WScreen
*scr
, char *cmdline
)
908 int ptr
, optr
, state
, len
, olen
;
910 char *selection
=NULL
;
911 char *user_input
=NULL
;
912 #if defined(OFFIX_DND) || defined(XDND)
913 char *dropped_thing
=NULL
;
915 char tmpbuf
[TMPBUFSIZE
];
918 len
= strlen(cmdline
);
922 wwarning(_("out of memory during expansion of \"%s\""));
926 ptr
= 0; /* input line pointer */
927 optr
= 0; /* output line pointer */
932 switch (cmdline
[ptr
]) {
941 out
[optr
++]=cmdline
[ptr
];
946 switch (cmdline
[ptr
]) {
960 out
[optr
++]=cmdline
[ptr
];
966 switch (cmdline
[ptr
]) {
968 if (scr
->focused_window
969 && scr
->focused_window
->flags
.focused
) {
970 sprintf(tmpbuf
, "0x%x",
971 (unsigned int)scr
->focused_window
->client_win
);
972 slen
= strlen(tmpbuf
);
974 nout
= realloc(out
,olen
);
976 wwarning(_("out of memory during expansion of \"%w\""));
988 sprintf(tmpbuf
, "0x%x",
989 (unsigned int)scr
->current_workspace
+ 1);
990 slen
= strlen(tmpbuf
);
992 nout
= realloc(out
,olen
);
994 wwarning(_("out of memory during expansion of \"%W\""));
1004 user_input
= getuserinput(scr
, cmdline
, &ptr
);
1006 slen
= strlen(user_input
);
1008 nout
= realloc(out
,olen
);
1010 wwarning(_("out of memory during expansion of \"%a\""));
1014 strcat(out
,user_input
);
1017 /* Not an error, but user has Canceled the dialog box.
1018 * This will make the command to not be performed. */
1023 #if defined(OFFIX_DND) || defined(XDND)
1026 if(scr
->xdestring
) {
1027 dropped_thing
= wstrdup(scr
->xdestring
);
1030 if (!dropped_thing
) {
1031 dropped_thing
= get_dnd_selection(scr
);
1033 if (!dropped_thing
) {
1034 scr
->flags
.dnd_data_convertion_status
= 1;
1037 slen
= strlen(dropped_thing
);
1039 nout
= realloc(out
,olen
);
1041 wwarning(_("out of memory during expansion of \"%d\""));
1045 strcat(out
,dropped_thing
);
1048 #endif /* OFFIX_DND */
1052 selection
= getselection(scr
);
1055 wwarning(_("selection not available"));
1058 slen
= strlen(selection
);
1060 nout
= realloc(out
,olen
);
1062 wwarning(_("out of memory during expansion of \"%s\""));
1066 strcat(out
,selection
);
1071 out
[optr
++]=cmdline
[ptr
];
1090 /* We don't care for upper/lower case in comparing the keys; so we
1091 have to define our own comparison function here */
1093 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
1097 str1
= PLGetString(pl1
);
1098 str2
= PLGetString(pl2
);
1100 if (strcasecmp(str1
, str2
)==0)
1107 /* feof doesn't seem to work on pipes */
1109 IsEof(FILE * stream
)
1111 static struct stat stinfo
;
1113 fstat(fileno(stream
), &stinfo
);
1114 return ((S_ISFIFO(stinfo
.st_dev
) && stinfo
.st_size
== 0) ||
1120 ParseWindowName(proplist_t value
, char **winstance
, char **wclass
, char *where
)
1124 *winstance
= *wclass
= NULL
;
1126 if (!PLIsString(value
)) {
1127 wwarning(_("bad window name value in %s state info"), where
);
1131 name
= PLGetString(value
);
1132 if (!name
|| strlen(name
)==0) {
1133 wwarning(_("bad window name value in %s state info"), where
);
1137 UnescapeWM_CLASS(name
, winstance
, wclass
);
1143 keysymToString(KeySym keysym
, unsigned int state
)
1146 char *buf
= wmalloc(20);
1150 kev
.type
= KeyPress
;
1151 kev
.send_event
= False
;
1152 kev
.window
= DefaultRootWindow(dpy
);
1153 kev
.root
= DefaultRootWindow(dpy
);
1154 kev
.same_screen
= True
;
1155 kev
.subwindow
= kev
.root
;
1156 kev
.serial
= 0x12344321;
1157 kev
.time
= CurrentTime
;
1159 kev
.keycode
= XKeysymToKeycode(dpy
, keysym
);
1160 count
= XLookupString(&kev
, buf
, 19, NULL
, NULL
);
1168 GetShortcutString(char *text
)
1170 char *buffer
= NULL
;
1177 tmp
= text
= wstrdup(text
);
1180 while ((k
= strchr(text
, '+'))!=NULL
) {
1184 mod
= wXModifierFromKey(text
);
1186 return wstrdup("bug");
1191 if (strcasecmp(text
, "Meta")==0) {
1192 buffer
= wstrappend(buffer
, "M+");
1193 } else if (strcasecmp(text
, "Alt")==0) {
1194 buffer
= wstrappend(buffer
, "A+");
1195 } else if (strcasecmp(text
, "Shift")==0) {
1196 buffer
= wstrappend(buffer
, "Sh+");
1197 } else if (strcasecmp(text
, "Mod1")==0) {
1198 buffer
= wstrappend(buffer
, "M1+");
1199 } else if (strcasecmp(text
, "Mod2")==0) {
1200 buffer
= wstrappend(buffer
, "M2+");
1201 } else if (strcasecmp(text
, "Mod3")==0) {
1202 buffer
= wstrappend(buffer
, "M3+");
1203 } else if (strcasecmp(text
, "Mod4")==0) {
1204 buffer
= wstrappend(buffer
, "M4+");
1205 } else if (strcasecmp(text
, "Mod5")==0) {
1206 buffer
= wstrappend(buffer
, "M5+");
1207 } else if (strcasecmp(text
, "Control")==0) {
1210 buffer
= wstrappend(buffer
, text
);
1216 buffer
= wstrappend(buffer
, "^");
1218 buffer
= wstrappend(buffer
, text
);
1221 /* ksym = XStringToKeysym(text);
1222 tmp = keysymToString(ksym, modmask);
1224 buffer = wstrappend(buffer, tmp);
1233 EscapeWM_CLASS(char *name
, char *class)
1236 char *ename
= NULL
, *eclass
= NULL
;
1239 if (!name
&& !class)
1244 ename
= wmalloc(l
*2);
1246 for (i
=0; i
<l
; i
++) {
1247 if (name
[i
]=='\\') {
1249 } else if (name
[i
]=='.') {
1252 ename
[j
++] = name
[i
];
1258 eclass
= wmalloc(l
*2);
1260 for (i
=0; i
<l
; i
++) {
1261 if (class[i
]=='\\') {
1263 } else if (class[i
]=='.') {
1266 eclass
[j
++] = class[i
];
1271 if (ename
&& eclass
) {
1272 ret
= wmalloc(strlen(ename
)+strlen(eclass
)+4);
1273 sprintf(ret
, "%s.%s", ename
, eclass
);
1277 ret
= wstrdup(ename
);
1280 ret
= wstrdup(eclass
);
1289 UnescapeWM_CLASS(char *str
, char **name
, char **class)
1297 *class = wmalloc(j
);
1300 /* separate string in 2 parts */
1303 for (i
= 0; i
< j
; i
++) {
1307 } else if (str
[i
]=='.') {
1316 /* unescape strings */
1319 for (i
= 0; i
< dot
; i
++) {
1324 (*name
)[k
++] = str
[i
];
1327 (*name
)[k
++] = str
[i
];
1335 for (i
= dot
+1; i
<j
; i
++) {
1340 (*class)[k
++] = str
[i
];
1361 SendHelperMessage(WScreen
*scr
, char type
, int workspace
, char *msg
)
1363 unsigned char *buffer
;
1368 if (!scr
->flags
.backimage_helper_launched
) {
1372 len
= (msg
? strlen(msg
) : 0) + (workspace
>=0 ? 4 : 0) + 1 ;
1373 buffer
= wmalloc(len
+5);
1374 sprintf(buf
, "%4i", len
);
1375 memcpy(buffer
, buf
, 4);
1378 if (workspace
>= 0) {
1379 sprintf(buf
, "%4i", workspace
);
1380 memcpy(&buffer
[i
], buf
, 4);
1385 strcpy(&buffer
[i
], msg
);
1387 if (write(scr
->helper_fd
, buffer
, len
+4) < 0) {
1388 wsyserror(_("could not send message to background image helper"));