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
35 #include "statusbar.h"
40 #include "layouts/tile.h"
42 extern AwesomeConf globalconf
;
46 /** Execute another process, replacing the current instance of Awesome
47 * \param screen Screen ID
49 * \ingroup ui_callback
52 uicb_exec(int screen
__attribute__ ((unused
)), char *cmd
)
58 /* remap all clients since some WM won't handle them otherwise */
59 for(c
= globalconf
.clients
; c
; c
= c
->next
)
62 XSync(globalconf
.display
, False
);
64 if(globalconf
.display
)
65 close(ConnectionNumber(globalconf
.display
));
67 /* Ignore the leading spaces if any */
69 args_pos
< strlen(cmd
) && cmd
[args_pos
] == ' ';
72 /* Get the beginning of the arguments */
73 if((args
= strchr(cmd
+ args_pos
, ' ')) == NULL
)
75 warn("Invalid command %s\n", cmd
);
79 path
= strndup(cmd
+ args_pos
, args
- (cmd
+ args_pos
));
80 execlp(path
, cmd
, NULL
);
84 /** Spawn another process
85 * \param screen Screen ID
87 * \ingroup ui_callback
90 uicb_spawn(int screen
, char *arg
)
92 static char *shell
= NULL
;
94 char *tmp
, newdisplay
[128];
99 if(!shell
&& !(shell
= getenv("SHELL")))
100 shell
= a_strdup("/bin/sh");
102 if(!globalconf
.screens_info
->xinerama_is_active
&& (tmp
= getenv("DISPLAY")))
104 display
= a_strdup(tmp
);
105 if((tmp
= strrchr(display
, '.')))
107 snprintf(newdisplay
, sizeof(newdisplay
), "%s.%d", display
, screen
);
108 setenv("DISPLAY", newdisplay
, 1);
112 /* The double-fork construct avoids zombie processes and keeps the code
113 * clean from stupid signal handlers. */
118 if(globalconf
.display
)
119 close(ConnectionNumber(globalconf
.display
));
121 execl(shell
, shell
, "-c", arg
, NULL
);
122 warn("execl '%s -c %s'", shell
, arg
);
140 p
= strtok(cmd
, " ");
143 warn("Ignoring malformed command\n");
147 if(screen
>= globalconf
.screens_info
->nscreen
|| screen
< 0)
149 warn("Invalid screen specified: %i\n", screen
);
153 p
= strtok(NULL
, " ");
156 warn("Ignoring malformed command.\n");
160 uicb
= name_func_lookup(p
, UicbList
);
163 warn("Unknown UICB function: %s.\n", p
);
167 if (p
+ a_strlen(p
) < cmd
+ len
)
169 arg
= p
+ a_strlen(p
) + 1;
171 /* Allow our callees to modify this string. */
172 argcpy
= p_new(char, len
+ 1);
173 a_strncpy(argcpy
, len
+ 1, arg
, len
);
174 uicb(screen
, argcpy
);
184 parse_control(char *cmd
)
186 char *p
, *curcmd
= cmd
;
191 while((p
= strchr(curcmd
, '\n')))
201 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80