2 * uicb.c - user interface callbacks management
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * @defgroup ui_callback User Interface Callbacks
26 #include <X11/extensions/Xinerama.h>
32 #include "statusbar.h"
37 #include "layouts/tile.h"
39 extern AwesomeConf globalconf
;
43 /** Execute another process, replacing the current instance of Awesome
44 * \param screen Screen ID
46 * \ingroup ui_callback
49 uicb_exec(int screen
__attribute__ ((unused
)), char *arg
)
54 /* remap all clients since some WM won't handle them otherwise */
55 for(c
= globalconf
.clients
; c
; c
= c
->next
)
58 XSync(globalconf
.display
, False
);
60 if(globalconf
.display
)
61 close(ConnectionNumber(globalconf
.display
));
63 sscanf(arg
, "%s", path
);
64 execlp(path
, arg
, NULL
);
67 /** Spawn another process
68 * \param screen Screen ID
70 * \ingroup ui_callback
73 uicb_spawn(int screen
, char *arg
)
75 static char *shell
= NULL
;
77 char *tmp
, newdisplay
[128];
82 if(!shell
&& !(shell
= getenv("SHELL")))
83 shell
= a_strdup("/bin/sh");
85 if(!XineramaIsActive(globalconf
.display
) && (tmp
= getenv("DISPLAY")))
87 display
= a_strdup(tmp
);
88 if((tmp
= strrchr(display
, '.')))
90 snprintf(newdisplay
, sizeof(newdisplay
), "%s.%d", display
, screen
);
91 setenv("DISPLAY", newdisplay
, 1);
95 /* The double-fork construct avoids zombie processes and keeps the code
96 * clean from stupid signal handlers. */
101 if(globalconf
.display
)
102 close(ConnectionNumber(globalconf
.display
));
104 execl(shell
, shell
, "-c", arg
, NULL
);
105 warn("execl '%s -c %s'", shell
, arg
);
123 p
= strtok(cmd
, " ");
126 warn("Ignoring malformed command\n");
130 if(screen
>= globalconf
.nscreen
|| screen
< 0)
132 warn("Invalid screen specified: %i\n", screen
);
136 p
= strtok(NULL
, " ");
139 warn("Ignoring malformed command.\n");
143 uicb
= name_func_lookup(p
, UicbList
);
146 warn("Unknown UICB function: %s.\n", p
);
150 if (p
+ a_strlen(p
) < cmd
+ len
)
152 arg
= p
+ a_strlen(p
) + 1;
154 /* Allow our callees to modify this string. */
155 argcpy
= p_new(char, len
+ 1);
156 a_strncpy(argcpy
, len
+ 1, arg
, len
);
157 uicb(screen
, argcpy
);
167 parse_control(char *cmd
)
169 char *p
, *curcmd
= cmd
;
174 while((p
= strchr(curcmd
, '\n')))
184 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80