Use xmalloc() instead of malloc().
[gwm.git] / actions.c
blobdc6f4269315912f4c752a0ae9b4acf776ab21396
1 /*
2 * actions.c
4 * Part of gwm, the Gratuitous Window Manager,
5 * by Gary Wong, <gtw@gnu.org>.
7 * Copyright (C) 2009 Gary Wong
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of version 3 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * $Id$
24 #include <config.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #if HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31 #include <xcb/xcb.h>
33 #include "gwm.h"
35 #include "actions.h"
36 #include "window-table.h"
38 static void external_command( char *name, ... ) {
40 if( !fork() ) {
41 va_list val;
42 int n;
43 char **args;
45 va_start( val, name );
46 for( n = 0; va_arg( val, char * ); n++ )
48 va_end( val );
50 args = alloca( ( n + 2 ) * sizeof *args );
52 args[ 0 ] = name;
54 va_start( val, name );
55 n = 1;
56 while( ( args[ n++ ] = va_arg( val, char * ) ) )
58 va_end( val );
60 setpgid( 0, 0 );
62 execvp( name, args );
64 _exit( 1 );
68 extern void action_raise_lowest( struct gwm_window *window,
69 xcb_generic_event_t *ev ) {
71 if( focus_frame )
72 xcb_circulate_window( c, XCB_CIRCULATE_RAISE_LOWEST,
73 screens[ focus_frame->screen ]->root );
76 extern void action_stack_opposite( struct gwm_window *window,
77 xcb_generic_event_t *ev ) {
79 if( focus_frame ) {
80 uint32_t n = XCB_STACK_MODE_OPPOSITE;
82 xcb_configure_window( c, focus_frame->w, XCB_CONFIG_WINDOW_STACK_MODE,
83 &n );
87 extern void action_map_all_icons( struct gwm_window *window,
88 xcb_generic_event_t *ev ) {
90 int i;
92 for( i = 0; i < windows.used; i++ )
93 if( windows.values[ i ]->type == WINDOW_MANAGED &&
94 windows.values[ i ]->u.managed.state == STATE_ICONIC )
95 iconic_to_normal( windows.values[ i ] );
98 extern void action_start_xterm( struct gwm_window *window,
99 xcb_generic_event_t *ev ) {
101 external_command( "xterm", NULL );