<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>i3: src/config.c Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.2-20100208 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <h1>src/config.c</h1><a href="a00062.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * vim:ts=8:expandtab</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * i3 - an improved dynamic tiling window manager</span> <a name="l00005"></a>00005 <span class="comment"> *</span> <a name="l00006"></a>00006 <span class="comment"> * © 2009-2010 Michael Stapelberg and contributors</span> <a name="l00007"></a>00007 <span class="comment"> *</span> <a name="l00008"></a>00008 <span class="comment"> * See file LICENSE for license information.</span> <a name="l00009"></a>00009 <span class="comment"> *</span> <a name="l00010"></a>00010 <span class="comment"> * src/config.c: Contains all functions handling the configuration file (calling</span> <a name="l00011"></a>00011 <span class="comment"> * the parser (src/cfgparse.y) with the correct path, switching key bindings</span> <a name="l00012"></a>00012 <span class="comment"> * mode).</span> <a name="l00013"></a>00013 <span class="comment"> *</span> <a name="l00014"></a>00014 <span class="comment"> */</span> <a name="l00015"></a>00015 <span class="preprocessor">#include <stdio.h></span> <a name="l00016"></a>00016 <span class="preprocessor">#include <string.h></span> <a name="l00017"></a>00017 <span class="preprocessor">#include <sys/stat.h></span> <a name="l00018"></a>00018 <span class="preprocessor">#include <sys/types.h></span> <a name="l00019"></a>00019 <span class="preprocessor">#include <stdlib.h></span> <a name="l00020"></a>00020 <span class="preprocessor">#include <glob.h></span> <a name="l00021"></a>00021 <span class="preprocessor">#include <wordexp.h></span> <a name="l00022"></a>00022 <span class="preprocessor">#include <unistd.h></span> <a name="l00023"></a>00023 <a name="l00024"></a>00024 <span class="comment">/* We need Xlib for XStringToKeysym */</span> <a name="l00025"></a>00025 <span class="preprocessor">#include <X11/Xlib.h></span> <a name="l00026"></a>00026 <a name="l00027"></a>00027 <span class="preprocessor">#include <xcb/xcb_keysyms.h></span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="a00041.html">i3.h</a>"</span> <a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="a00052.html">util.h</a>"</span> <a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="a00034.html">config.h</a>"</span> <a name="l00032"></a>00032 <span class="preprocessor">#include "<a class="code" href="a00054.html">xcb.h</a>"</span> <a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="a00051.html">table.h</a>"</span> <a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="a00053.html">workspace.h</a>"</span> <a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="a00044.html">log.h</a>"</span> <a name="l00036"></a>00036 <a name="l00037"></a><a class="code" href="a00034.html#a4a8dd3a2de125b72d4fe6251a0a271b5">00037</a> <a class="code" href="a00010.html" title="Holds part of the configuration (the part which is not already in dedicated structures...">Config</a> <a class="code" href="a00062.html#a4a8dd3a2de125b72d4fe6251a0a271b5">config</a>; <a name="l00038"></a><a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">00038</a> <span class="keyword">struct </span>modes_head <a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">modes</a>; <a name="l00039"></a>00039 <a name="l00040"></a>00040 <span class="comment">/*</span> <a name="l00041"></a>00041 <span class="comment"> * This function resolves ~ in pathnames.</span> <a name="l00042"></a>00042 <span class="comment"> *</span> <a name="l00043"></a>00043 <span class="comment"> */</span> <a name="l00044"></a><a class="code" href="a00034.html#aea199116bec04e7987dad157e10b49b5">00044</a> <span class="keywordtype">char</span> *<a class="code" href="a00062.html#aea199116bec04e7987dad157e10b49b5" title="This function resolves ~ in pathnames.">glob_path</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *path) { <a name="l00045"></a>00045 <span class="keyword">static</span> glob_t globbuf; <a name="l00046"></a>00046 <span class="keywordflow">if</span> (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0) <a name="l00047"></a>00047 <a class="code" href="a00052.html#a0b2164ee75646f16a7388a36e6800c35">die</a>(<span class="stringliteral">"glob() failed"</span>); <a name="l00048"></a>00048 <span class="keywordtype">char</span> *result = <a class="code" href="a00077.html#a11822d1f4b182be3fa03d2a5af536e1a" title="Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there...">sstrdup</a>(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path); <a name="l00049"></a>00049 globfree(&globbuf); <a name="l00050"></a>00050 <a name="l00051"></a>00051 <span class="comment">/* If the file does not exist yet, we still may need to resolve tilde,</span> <a name="l00052"></a>00052 <span class="comment"> * so call wordexp */</span> <a name="l00053"></a>00053 <span class="keywordflow">if</span> (strcmp(result, path) == 0) { <a name="l00054"></a>00054 wordexp_t we; <a name="l00055"></a>00055 wordexp(path, &we, WRDE_NOCMD); <a name="l00056"></a>00056 <span class="keywordflow">if</span> (we.we_wordc > 0) { <a name="l00057"></a>00057 free(result); <a name="l00058"></a>00058 result = <a class="code" href="a00077.html#a11822d1f4b182be3fa03d2a5af536e1a" title="Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there...">sstrdup</a>(we.we_wordv[0]); <a name="l00059"></a>00059 } <a name="l00060"></a>00060 wordfree(&we); <a name="l00061"></a>00061 } <a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="keywordflow">return</span> result; <a name="l00064"></a>00064 } <a name="l00065"></a>00065 <a name="l00066"></a>00066 <span class="comment">/*</span> <a name="l00067"></a>00067 <span class="comment"> * Checks if the given path exists by calling stat().</span> <a name="l00068"></a>00068 <span class="comment"> *</span> <a name="l00069"></a>00069 <span class="comment"> */</span> <a name="l00070"></a><a class="code" href="a00034.html#a7c81151479c55671cd41ad9d1b3d3f52">00070</a> <span class="keywordtype">bool</span> <a class="code" href="a00062.html#a7c81151479c55671cd41ad9d1b3d3f52" title="Checks if the given path exists by calling stat().">path_exists</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *path) { <a name="l00071"></a>00071 <span class="keyword">struct </span>stat buf; <a name="l00072"></a>00072 <span class="keywordflow">return</span> (stat(path, &buf) == 0); <a name="l00073"></a>00073 } <a name="l00074"></a>00074 <a name="l00080"></a><a class="code" href="a00034.html#afa95dc10a37decc54e9a376d0d462048">00080</a> <span class="keywordtype">void</span> <a class="code" href="a00062.html#afa95dc10a37decc54e9a376d0d462048" title="Ungrabs all keys, to be called before re-grabbing the keys because of a mapping_notify...">ungrab_all_keys</a>(xcb_connection_t *conn) { <a name="l00081"></a>00081 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Ungrabbing all keys\n"</span>); <a name="l00082"></a>00082 xcb_ungrab_key(conn, XCB_GRAB_ANY, <a class="code" href="a00071.html#a768f07da9e11ab88732a5c550ff49257">root</a>, XCB_BUTTON_MASK_ANY); <a name="l00083"></a>00083 } <a name="l00084"></a>00084 <a name="l00085"></a><a class="code" href="a00062.html#aaa0dba2e97ed49099bbecc084fec0021">00085</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="a00062.html#aaa0dba2e97ed49099bbecc084fec0021">grab_keycode_for_binding</a>(xcb_connection_t *conn, <a class="code" href="a00003.html" title="Holds a keybinding, consisting of a keycode combined with modifiers and the command...">Binding</a> *bind, uint32_t keycode) { <a name="l00086"></a>00086 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Grabbing %d\n"</span>, keycode); <a name="l00087"></a>00087 <span class="comment">/* Grab the key in all combinations */</span> <a name="l00088"></a>00088 <span class="preprocessor"> #define GRAB_KEY(modifier) \</span> <a name="l00089"></a>00089 <span class="preprocessor"> do { \</span> <a name="l00090"></a>00090 <span class="preprocessor"> xcb_grab_key(conn, 0, root, modifier, keycode, \</span> <a name="l00091"></a>00091 <span class="preprocessor"> XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC); \</span> <a name="l00092"></a>00092 <span class="preprocessor"> } while (0)</span> <a name="l00093"></a>00093 <span class="preprocessor"></span> <span class="keywordtype">int</span> mods = bind-><a class="code" href="a00003.html#ac1d18080d951bafa7ee0a291aade6e07" title="Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, ….">mods</a>; <a name="l00094"></a>00094 <span class="keywordflow">if</span> ((bind-><a class="code" href="a00003.html#ac1d18080d951bafa7ee0a291aade6e07" title="Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, ….">mods</a> & <a class="code" href="a00036.html#a06fc87d81c62e9abb8790b6e5713c55ba059099ea410e7b545a26cefafe4b8358">BIND_MODE_SWITCH</a>) != 0) { <a name="l00095"></a>00095 mods &= ~<a class="code" href="a00036.html#a06fc87d81c62e9abb8790b6e5713c55ba059099ea410e7b545a26cefafe4b8358">BIND_MODE_SWITCH</a>; <a name="l00096"></a>00096 <span class="keywordflow">if</span> (mods == 0) <a name="l00097"></a>00097 mods = XCB_MOD_MASK_ANY; <a name="l00098"></a>00098 } <a name="l00099"></a>00099 <a class="code" href="a00062.html#a7b96960c81da5ecedc1d584069d9447c">GRAB_KEY</a>(mods); <a name="l00100"></a>00100 <a class="code" href="a00062.html#a7b96960c81da5ecedc1d584069d9447c">GRAB_KEY</a>(mods | <a class="code" href="a00054.html#ac430ae06cbf6f5ef252c9ebfca47e644">xcb_numlock_mask</a>); <a name="l00101"></a>00101 <a class="code" href="a00062.html#a7b96960c81da5ecedc1d584069d9447c">GRAB_KEY</a>(mods | <a class="code" href="a00054.html#ac430ae06cbf6f5ef252c9ebfca47e644">xcb_numlock_mask</a> | XCB_MOD_MASK_LOCK); <a name="l00102"></a>00102 } <a name="l00103"></a>00103 <a name="l00104"></a>00104 <span class="comment">/*</span> <a name="l00105"></a>00105 <span class="comment"> * Returns a pointer to the Binding with the specified modifiers and keycode</span> <a name="l00106"></a>00106 <span class="comment"> * or NULL if no such binding exists.</span> <a name="l00107"></a>00107 <span class="comment"> *</span> <a name="l00108"></a>00108 <span class="comment"> */</span> <a name="l00109"></a><a class="code" href="a00034.html#afc938201ea536eed0f0838bb3c4c5c2c">00109</a> <a class="code" href="a00003.html" title="Holds a keybinding, consisting of a keycode combined with modifiers and the command...">Binding</a> *<a class="code" href="a00062.html#afc938201ea536eed0f0838bb3c4c5c2c" title="Returns a pointer to the Binding with the specified modifiers and keycode or NULL...">get_binding</a>(uint16_t modifiers, xcb_keycode_t keycode) { <a name="l00110"></a>00110 <a class="code" href="a00003.html" title="Holds a keybinding, consisting of a keycode combined with modifiers and the command...">Binding</a> *bind; <a name="l00111"></a>00111 <a name="l00112"></a>00112 <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(bind, <a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>, <a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>) { <a name="l00113"></a>00113 <span class="comment">/* First compare the modifiers */</span> <a name="l00114"></a>00114 <span class="keywordflow">if</span> (bind-><a class="code" href="a00003.html#ac1d18080d951bafa7ee0a291aade6e07" title="Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, ….">mods</a> != modifiers) <a name="l00115"></a>00115 <span class="keywordflow">continue</span>; <a name="l00116"></a>00116 <a name="l00117"></a>00117 <span class="comment">/* If a symbol was specified by the user, we need to look in</span> <a name="l00118"></a>00118 <span class="comment"> * the array of translated keycodes for the event’s keycode */</span> <a name="l00119"></a>00119 <span class="keywordflow">if</span> (bind-><a class="code" href="a00003.html#a82bca43f02debcb9125c8c3f650a573d" title="Symbol the user specified in configfile, if any.">symbol</a> != NULL) { <a name="l00120"></a>00120 <span class="keywordflow">if</span> (memmem(bind-><a class="code" href="a00003.html#a66527e5582bc56a6bae1f08fa3af55cb" title="Only in use if symbol != NULL.">translated_to</a>, <a name="l00121"></a>00121 bind-><a class="code" href="a00003.html#add9435ea373eaa4edab185fc41f69ecc">number_keycodes</a> * <span class="keyword">sizeof</span>(xcb_keycode_t), <a name="l00122"></a>00122 &keycode, <span class="keyword">sizeof</span>(xcb_keycode_t)) != NULL) <a name="l00123"></a>00123 <span class="keywordflow">break</span>; <a name="l00124"></a>00124 } <span class="keywordflow">else</span> { <a name="l00125"></a>00125 <span class="comment">/* This case is easier: The user specified a keycode */</span> <a name="l00126"></a>00126 <span class="keywordflow">if</span> (bind-><a class="code" href="a00003.html#a7f033747baf05a7cdbe176afdddab7e6" title="Keycode to bind.">keycode</a> == keycode) <a name="l00127"></a>00127 <span class="keywordflow">break</span>; <a name="l00128"></a>00128 } <a name="l00129"></a>00129 } <a name="l00130"></a>00130 <a name="l00131"></a>00131 <span class="keywordflow">return</span> (bind == <a class="code" href="a00047.html#a4322b8461a6ab7632435ff4f57bb3a2e">TAILQ_END</a>(<a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>) ? NULL : bind); <a name="l00132"></a>00132 } <a name="l00133"></a>00133 <a name="l00134"></a>00134 <span class="comment">/*</span> <a name="l00135"></a>00135 <span class="comment"> * Translates keysymbols to keycodes for all bindings which use keysyms.</span> <a name="l00136"></a>00136 <span class="comment"> *</span> <a name="l00137"></a>00137 <span class="comment"> */</span> <a name="l00138"></a><a class="code" href="a00034.html#a0ee8ffa5c11aeb96126b36171da84adc">00138</a> <span class="keywordtype">void</span> <a class="code" href="a00062.html#a0ee8ffa5c11aeb96126b36171da84adc" title="Translates keysymbols to keycodes for all bindings which use keysyms.">translate_keysyms</a>() { <a name="l00139"></a>00139 <a class="code" href="a00003.html" title="Holds a keybinding, consisting of a keycode combined with modifiers and the command...">Binding</a> *bind; <a name="l00140"></a>00140 <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(bind, <a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>, <a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>) { <a name="l00141"></a>00141 <span class="keywordflow">if</span> (bind-><a class="code" href="a00003.html#a7f033747baf05a7cdbe176afdddab7e6" title="Keycode to bind.">keycode</a> > 0) <a name="l00142"></a>00142 <span class="keywordflow">continue</span>; <a name="l00143"></a>00143 <a name="l00144"></a>00144 <span class="comment">/* We need to translate the symbol to a keycode */</span> <a name="l00145"></a>00145 xcb_keysym_t keysym = XStringToKeysym(bind-><a class="code" href="a00003.html#a82bca43f02debcb9125c8c3f650a573d" title="Symbol the user specified in configfile, if any.">symbol</a>); <a name="l00146"></a>00146 <span class="keywordflow">if</span> (keysym == NoSymbol) { <a name="l00147"></a>00147 <a class="code" href="a00044.html#a6828c68e0feb4b7fdfe0fc3ba9f3038b">ELOG</a>(<span class="stringliteral">"Could not translate string to key symbol: \"%s\"\n"</span>, bind-><a class="code" href="a00003.html#a82bca43f02debcb9125c8c3f650a573d" title="Symbol the user specified in configfile, if any.">symbol</a>); <a name="l00148"></a>00148 <span class="keywordflow">continue</span>; <a name="l00149"></a>00149 } <a name="l00150"></a>00150 <a name="l00151"></a>00151 <span class="preprocessor">#ifdef OLD_XCB_KEYSYMS_API</span> <a name="l00152"></a>00152 <span class="preprocessor"></span> bind-><a class="code" href="a00003.html#add9435ea373eaa4edab185fc41f69ecc">number_keycodes</a> = 1; <a name="l00153"></a>00153 xcb_keycode_t code = xcb_key_symbols_get_keycode(<a class="code" href="a00071.html#a5cc0138ae2cf3bbb63a7cae907620797">keysyms</a>, keysym); <a name="l00154"></a>00154 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Translated symbol \"%s\" to 1 keycode (%d)\n"</span>, bind-><a class="code" href="a00003.html#a82bca43f02debcb9125c8c3f650a573d" title="Symbol the user specified in configfile, if any.">symbol</a>, code); <a name="l00155"></a>00155 <a class="code" href="a00062.html#aaa0dba2e97ed49099bbecc084fec0021">grab_keycode_for_binding</a>(<a class="code" href="a00071.html#ada13c42121d64521629e06e7a5e1db16">global_conn</a>, bind, code); <a name="l00156"></a>00156 bind-><a class="code" href="a00003.html#a66527e5582bc56a6bae1f08fa3af55cb" title="Only in use if symbol != NULL.">translated_to</a> = <a class="code" href="a00077.html#a46c23cb2833f4b674f5cfc977f16b990" title="Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there...">smalloc</a>(<span class="keyword">sizeof</span>(xcb_keycode_t)); <a name="l00157"></a>00157 memcpy(bind-><a class="code" href="a00003.html#a66527e5582bc56a6bae1f08fa3af55cb" title="Only in use if symbol != NULL.">translated_to</a>, &code, <span class="keyword">sizeof</span>(xcb_keycode_t)); <a name="l00158"></a>00158 <span class="preprocessor">#else</span> <a name="l00159"></a>00159 <span class="preprocessor"></span> uint32_t last_keycode = 0; <a name="l00160"></a>00160 xcb_keycode_t *keycodes = xcb_key_symbols_get_keycode(<a class="code" href="a00071.html#a5cc0138ae2cf3bbb63a7cae907620797">keysyms</a>, keysym); <a name="l00161"></a>00161 <span class="keywordflow">if</span> (keycodes == NULL) { <a name="l00162"></a>00162 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Could not translate symbol \"%s\"\n"</span>, bind-><a class="code" href="a00003.html#a82bca43f02debcb9125c8c3f650a573d" title="Symbol the user specified in configfile, if any.">symbol</a>); <a name="l00163"></a>00163 <span class="keywordflow">continue</span>; <a name="l00164"></a>00164 } <a name="l00165"></a>00165 <a name="l00166"></a>00166 bind-><a class="code" href="a00003.html#add9435ea373eaa4edab185fc41f69ecc">number_keycodes</a> = 0; <a name="l00167"></a>00167 <a name="l00168"></a>00168 <span class="keywordflow">for</span> (xcb_keycode_t *walk = keycodes; *walk != 0; walk++) { <a name="l00169"></a>00169 <span class="comment">/* We hope duplicate keycodes will be returned in order</span> <a name="l00170"></a>00170 <span class="comment"> * and skip them */</span> <a name="l00171"></a>00171 <span class="keywordflow">if</span> (last_keycode == *walk) <a name="l00172"></a>00172 <span class="keywordflow">continue</span>; <a name="l00173"></a>00173 last_keycode = *walk; <a name="l00174"></a>00174 bind-><a class="code" href="a00003.html#add9435ea373eaa4edab185fc41f69ecc">number_keycodes</a>++; <a name="l00175"></a>00175 } <a name="l00176"></a>00176 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Translated symbol \"%s\" to %d keycode\n"</span>, bind-><a class="code" href="a00003.html#a82bca43f02debcb9125c8c3f650a573d" title="Symbol the user specified in configfile, if any.">symbol</a>, bind-><a class="code" href="a00003.html#add9435ea373eaa4edab185fc41f69ecc">number_keycodes</a>); <a name="l00177"></a>00177 bind-><a class="code" href="a00003.html#a66527e5582bc56a6bae1f08fa3af55cb" title="Only in use if symbol != NULL.">translated_to</a> = <a class="code" href="a00077.html#a46c23cb2833f4b674f5cfc977f16b990" title="Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there...">smalloc</a>(bind-><a class="code" href="a00003.html#add9435ea373eaa4edab185fc41f69ecc">number_keycodes</a> * <span class="keyword">sizeof</span>(xcb_keycode_t)); <a name="l00178"></a>00178 memcpy(bind-><a class="code" href="a00003.html#a66527e5582bc56a6bae1f08fa3af55cb" title="Only in use if symbol != NULL.">translated_to</a>, keycodes, bind-><a class="code" href="a00003.html#add9435ea373eaa4edab185fc41f69ecc">number_keycodes</a> * <span class="keyword">sizeof</span>(xcb_keycode_t)); <a name="l00179"></a>00179 free(keycodes); <a name="l00180"></a>00180 <span class="preprocessor">#endif</span> <a name="l00181"></a>00181 <span class="preprocessor"></span> } <a name="l00182"></a>00182 } <a name="l00183"></a>00183 <a name="l00184"></a>00184 <span class="comment">/*</span> <a name="l00185"></a>00185 <span class="comment"> * Grab the bound keys (tell X to send us keypress events for those keycodes)</span> <a name="l00186"></a>00186 <span class="comment"> *</span> <a name="l00187"></a>00187 <span class="comment"> */</span> <a name="l00188"></a><a class="code" href="a00034.html#a1741cf749eb2243cca453355d3f6879b">00188</a> <span class="keywordtype">void</span> <a class="code" href="a00062.html#a1741cf749eb2243cca453355d3f6879b" title="Grab the bound keys (tell X to send us keypress events for those keycodes).">grab_all_keys</a>(xcb_connection_t *conn, <span class="keywordtype">bool</span> bind_mode_switch) { <a name="l00189"></a>00189 <a class="code" href="a00003.html" title="Holds a keybinding, consisting of a keycode combined with modifiers and the command...">Binding</a> *bind; <a name="l00190"></a>00190 <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(bind, <a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>, <a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>) { <a name="l00191"></a>00191 <span class="keywordflow">if</span> ((bind_mode_switch && (bind-><a class="code" href="a00003.html#ac1d18080d951bafa7ee0a291aade6e07" title="Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, ….">mods</a> & <a class="code" href="a00036.html#a06fc87d81c62e9abb8790b6e5713c55ba059099ea410e7b545a26cefafe4b8358">BIND_MODE_SWITCH</a>) == 0) || <a name="l00192"></a>00192 (!bind_mode_switch && (bind-><a class="code" href="a00003.html#ac1d18080d951bafa7ee0a291aade6e07" title="Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, ….">mods</a> & <a class="code" href="a00036.html#a06fc87d81c62e9abb8790b6e5713c55ba059099ea410e7b545a26cefafe4b8358">BIND_MODE_SWITCH</a>) != 0)) <a name="l00193"></a>00193 <span class="keywordflow">continue</span>; <a name="l00194"></a>00194 <a name="l00195"></a>00195 <span class="comment">/* The easy case: the user specified a keycode directly. */</span> <a name="l00196"></a>00196 <span class="keywordflow">if</span> (bind-><a class="code" href="a00003.html#a7f033747baf05a7cdbe176afdddab7e6" title="Keycode to bind.">keycode</a> > 0) { <a name="l00197"></a>00197 <a class="code" href="a00062.html#aaa0dba2e97ed49099bbecc084fec0021">grab_keycode_for_binding</a>(conn, bind, bind-><a class="code" href="a00003.html#a7f033747baf05a7cdbe176afdddab7e6" title="Keycode to bind.">keycode</a>); <a name="l00198"></a>00198 <span class="keywordflow">continue</span>; <a name="l00199"></a>00199 } <a name="l00200"></a>00200 <a name="l00201"></a>00201 xcb_keycode_t *walk = bind-><a class="code" href="a00003.html#a66527e5582bc56a6bae1f08fa3af55cb" title="Only in use if symbol != NULL.">translated_to</a>; <a name="l00202"></a>00202 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < bind-><a class="code" href="a00003.html#add9435ea373eaa4edab185fc41f69ecc">number_keycodes</a>; i++) <a name="l00203"></a>00203 <a class="code" href="a00062.html#aaa0dba2e97ed49099bbecc084fec0021">grab_keycode_for_binding</a>(conn, bind, *walk); <a name="l00204"></a>00204 } <a name="l00205"></a>00205 } <a name="l00206"></a>00206 <a name="l00207"></a>00207 <span class="comment">/*</span> <a name="l00208"></a>00208 <span class="comment"> * Switches the key bindings to the given mode, if the mode exists</span> <a name="l00209"></a>00209 <span class="comment"> *</span> <a name="l00210"></a>00210 <span class="comment"> */</span> <a name="l00211"></a><a class="code" href="a00034.html#a2ffac81a6e7d464474716e01da82c5df">00211</a> <span class="keywordtype">void</span> <a class="code" href="a00062.html#a2ffac81a6e7d464474716e01da82c5df" title="Switches the key bindings to the given mode, if the mode exists.">switch_mode</a>(xcb_connection_t *conn, <span class="keyword">const</span> <span class="keywordtype">char</span> *new_mode) { <a name="l00212"></a>00212 <span class="keyword">struct </span><a class="code" href="a00019.html" title="The configuration file can contain multiple sets of bindings.">Mode</a> *mode; <a name="l00213"></a>00213 <a name="l00214"></a>00214 <a class="code" href="a00044.html#a388edf12256bf73c3a8ee9734c3bd841" title="#__VA_ARGS__ means: leave out __VA_ARGS__ completely if it is empty, that is, delete...">LOG</a>(<span class="stringliteral">"Switching to mode %s\n"</span>, new_mode); <a name="l00215"></a>00215 <a name="l00216"></a>00216 <a class="code" href="a00047.html#a05db87878125c27e3060dd641aa3b0f4">SLIST_FOREACH</a>(mode, &<a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">modes</a>, <a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">modes</a>) { <a name="l00217"></a>00217 <span class="keywordflow">if</span> (strcasecmp(mode-><a class="code" href="a00019.html#a336e4d433ab15856ab40cdf207ddfd48">name</a>, new_mode) != 0) <a name="l00218"></a>00218 <span class="keywordflow">continue</span>; <a name="l00219"></a>00219 <a name="l00220"></a>00220 <a class="code" href="a00062.html#afa95dc10a37decc54e9a376d0d462048" title="Ungrabs all keys, to be called before re-grabbing the keys because of a mapping_notify...">ungrab_all_keys</a>(conn); <a name="l00221"></a>00221 <a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a> = mode-><a class="code" href="a00019.html#a57efc24f1118014a783ba82a80b73af3">bindings</a>; <a name="l00222"></a>00222 <a class="code" href="a00062.html#a0ee8ffa5c11aeb96126b36171da84adc" title="Translates keysymbols to keycodes for all bindings which use keysyms.">translate_keysyms</a>(); <a name="l00223"></a>00223 <a class="code" href="a00062.html#a1741cf749eb2243cca453355d3f6879b" title="Grab the bound keys (tell X to send us keypress events for those keycodes).">grab_all_keys</a>(conn, <span class="keyword">false</span>); <a name="l00224"></a>00224 <span class="keywordflow">return</span>; <a name="l00225"></a>00225 } <a name="l00226"></a>00226 <a name="l00227"></a>00227 <a class="code" href="a00044.html#a6828c68e0feb4b7fdfe0fc3ba9f3038b">ELOG</a>(<span class="stringliteral">"ERROR: Mode not found\n"</span>); <a name="l00228"></a>00228 } <a name="l00229"></a>00229 <a name="l00230"></a>00230 <span class="comment">/*</span> <a name="l00231"></a>00231 <span class="comment"> * Get the path of the first configuration file found. Checks the XDG folders</span> <a name="l00232"></a>00232 <span class="comment"> * first ($XDG_CONFIG_HOME, $XDG_CONFIG_DIRS), then the traditional paths.</span> <a name="l00233"></a>00233 <span class="comment"> *</span> <a name="l00234"></a>00234 <span class="comment"> */</span> <a name="l00235"></a><a class="code" href="a00062.html#ae3d7e99bd14d228645d8e223519a2827">00235</a> <span class="keyword">static</span> <span class="keywordtype">char</span> *<a class="code" href="a00062.html#ae3d7e99bd14d228645d8e223519a2827">get_config_path</a>() { <a name="l00236"></a>00236 <span class="comment">/* 1: check for $XDG_CONFIG_HOME/i3/config */</span> <a name="l00237"></a>00237 <span class="keywordtype">char</span> *xdg_config_home, *xdg_config_dirs, *config_path; <a name="l00238"></a>00238 <a name="l00239"></a>00239 <span class="keywordflow">if</span> ((xdg_config_home = getenv(<span class="stringliteral">"XDG_CONFIG_HOME"</span>)) == NULL) <a name="l00240"></a>00240 xdg_config_home = <span class="stringliteral">"~/.config"</span>; <a name="l00241"></a>00241 <a name="l00242"></a>00242 xdg_config_home = <a class="code" href="a00062.html#aea199116bec04e7987dad157e10b49b5" title="This function resolves ~ in pathnames.">glob_path</a>(xdg_config_home); <a name="l00243"></a>00243 <span class="keywordflow">if</span> (asprintf(&config_path, <span class="stringliteral">"%s/i3/config"</span>, xdg_config_home) == -1) <a name="l00244"></a>00244 <a class="code" href="a00052.html#a0b2164ee75646f16a7388a36e6800c35">die</a>(<span class="stringliteral">"asprintf() failed"</span>); <a name="l00245"></a>00245 free(xdg_config_home); <a name="l00246"></a>00246 <a name="l00247"></a>00247 <span class="keywordflow">if</span> (<a class="code" href="a00062.html#a7c81151479c55671cd41ad9d1b3d3f52" title="Checks if the given path exists by calling stat().">path_exists</a>(config_path)) <a name="l00248"></a>00248 <span class="keywordflow">return</span> config_path; <a name="l00249"></a>00249 free(config_path); <a name="l00250"></a>00250 <a name="l00251"></a>00251 <span class="comment">/* 2: check for $XDG_CONFIG_DIRS/i3/config */</span> <a name="l00252"></a>00252 <span class="keywordflow">if</span> ((xdg_config_dirs = getenv(<span class="stringliteral">"XDG_CONFIG_DIRS"</span>)) == NULL) <a name="l00253"></a>00253 xdg_config_dirs = <span class="stringliteral">"/etc/xdg"</span>; <a name="l00254"></a>00254 <a name="l00255"></a>00255 <span class="keywordtype">char</span> *buf = strdup(xdg_config_dirs); <a name="l00256"></a>00256 <span class="keywordtype">char</span> *tok = strtok(buf, <span class="stringliteral">":"</span>); <a name="l00257"></a>00257 <span class="keywordflow">while</span> (tok != NULL) { <a name="l00258"></a>00258 tok = <a class="code" href="a00062.html#aea199116bec04e7987dad157e10b49b5" title="This function resolves ~ in pathnames.">glob_path</a>(tok); <a name="l00259"></a>00259 <span class="keywordflow">if</span> (asprintf(&config_path, <span class="stringliteral">"%s/i3/config"</span>, tok) == -1) <a name="l00260"></a>00260 <a class="code" href="a00052.html#a0b2164ee75646f16a7388a36e6800c35">die</a>(<span class="stringliteral">"asprintf() failed"</span>); <a name="l00261"></a>00261 free(tok); <a name="l00262"></a>00262 <span class="keywordflow">if</span> (<a class="code" href="a00062.html#a7c81151479c55671cd41ad9d1b3d3f52" title="Checks if the given path exists by calling stat().">path_exists</a>(config_path)) { <a name="l00263"></a>00263 free(buf); <a name="l00264"></a>00264 <span class="keywordflow">return</span> config_path; <a name="l00265"></a>00265 } <a name="l00266"></a>00266 free(config_path); <a name="l00267"></a>00267 tok = strtok(NULL, <span class="stringliteral">":"</span>); <a name="l00268"></a>00268 } <a name="l00269"></a>00269 free(buf); <a name="l00270"></a>00270 <a name="l00271"></a>00271 <span class="comment">/* 3: check traditional paths */</span> <a name="l00272"></a>00272 config_path = <a class="code" href="a00062.html#aea199116bec04e7987dad157e10b49b5" title="This function resolves ~ in pathnames.">glob_path</a>(<span class="stringliteral">"~/.i3/config"</span>); <a name="l00273"></a>00273 <span class="keywordflow">if</span> (<a class="code" href="a00062.html#a7c81151479c55671cd41ad9d1b3d3f52" title="Checks if the given path exists by calling stat().">path_exists</a>(config_path)) <a name="l00274"></a>00274 <span class="keywordflow">return</span> config_path; <a name="l00275"></a>00275 <a name="l00276"></a>00276 config_path = strdup(<span class="stringliteral">"/etc/i3/config"</span>); <a name="l00277"></a>00277 <span class="keywordflow">if</span> (!<a class="code" href="a00062.html#a7c81151479c55671cd41ad9d1b3d3f52" title="Checks if the given path exists by calling stat().">path_exists</a>(config_path)) <a name="l00278"></a>00278 <a class="code" href="a00052.html#a0b2164ee75646f16a7388a36e6800c35">die</a>(<span class="stringliteral">"Neither $XDG_CONFIG_HOME/i3/config, nor "</span> <a name="l00279"></a>00279 <span class="stringliteral">"$XDG_CONFIG_DIRS/i3/config, nor ~/.i3/config nor "</span> <a name="l00280"></a>00280 <span class="stringliteral">"/etc/i3/config exist."</span>); <a name="l00281"></a>00281 <a name="l00282"></a>00282 <span class="keywordflow">return</span> config_path; <a name="l00283"></a>00283 } <a name="l00284"></a>00284 <a name="l00285"></a>00285 <span class="comment">/*</span> <a name="l00286"></a>00286 <span class="comment"> * Finds the configuration file to use (either the one specified by</span> <a name="l00287"></a>00287 <span class="comment"> * override_configpath), the user’s one or the system default) and calls</span> <a name="l00288"></a>00288 <span class="comment"> * parse_file().</span> <a name="l00289"></a>00289 <span class="comment"> *</span> <a name="l00290"></a>00290 <span class="comment"> */</span> <a name="l00291"></a><a class="code" href="a00062.html#a6f3a92013cf7e1ece6139b05a43a2c95">00291</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="a00062.html#a6f3a92013cf7e1ece6139b05a43a2c95">parse_configuration</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *override_configpath) { <a name="l00292"></a>00292 <span class="keywordflow">if</span> (override_configpath != NULL) { <a name="l00293"></a>00293 <a class="code" href="a00056.html#a41592f23fd361db6127ac0223f3063b2">parse_file</a>(override_configpath); <a name="l00294"></a>00294 <span class="keywordflow">return</span>; <a name="l00295"></a>00295 } <a name="l00296"></a>00296 <a name="l00297"></a>00297 <span class="keywordtype">char</span> *path = <a class="code" href="a00062.html#ae3d7e99bd14d228645d8e223519a2827">get_config_path</a>(); <a name="l00298"></a>00298 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Parsing configfile %s\n"</span>, path); <a name="l00299"></a>00299 <a class="code" href="a00056.html#a41592f23fd361db6127ac0223f3063b2">parse_file</a>(path); <a name="l00300"></a>00300 free(path); <a name="l00301"></a>00301 } <a name="l00302"></a>00302 <a name="l00303"></a>00303 <span class="comment">/*</span> <a name="l00304"></a>00304 <span class="comment"> * (Re-)loads the configuration file (sets useful defaults before).</span> <a name="l00305"></a>00305 <span class="comment"> *</span> <a name="l00306"></a>00306 <span class="comment"> */</span> <a name="l00307"></a><a class="code" href="a00034.html#a42a662960e335a91279653c3da1aa6f2">00307</a> <span class="keywordtype">void</span> <a class="code" href="a00062.html#a19bff8205cd2bd9492b5f95076dfa3a0" title="Reads the configuration from ~/.i3/config or /etc/i3/config if not found.">load_configuration</a>(xcb_connection_t *conn, <span class="keyword">const</span> <span class="keywordtype">char</span> *override_configpath, <span class="keywordtype">bool</span> reload) { <a name="l00308"></a>00308 <span class="keywordflow">if</span> (reload) { <a name="l00309"></a>00309 <span class="comment">/* First ungrab the keys */</span> <a name="l00310"></a>00310 <a class="code" href="a00062.html#afa95dc10a37decc54e9a376d0d462048" title="Ungrabs all keys, to be called before re-grabbing the keys because of a mapping_notify...">ungrab_all_keys</a>(conn); <a name="l00311"></a>00311 <a name="l00312"></a>00312 <span class="keyword">struct </span><a class="code" href="a00019.html" title="The configuration file can contain multiple sets of bindings.">Mode</a> *mode; <a name="l00313"></a>00313 <a class="code" href="a00003.html" title="Holds a keybinding, consisting of a keycode combined with modifiers and the command...">Binding</a> *bind; <a name="l00314"></a>00314 <span class="keywordflow">while</span> (!<a class="code" href="a00047.html#a59bcc4e6f4bf63b897bdc0644566c583">SLIST_EMPTY</a>(&<a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">modes</a>)) { <a name="l00315"></a>00315 mode = <a class="code" href="a00047.html#a91bac7d0d32e3ec56bc579ace45ed8cd">SLIST_FIRST</a>(&<a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">modes</a>); <a name="l00316"></a>00316 <a class="code" href="a00052.html#ae88e84de75be0b138a19509d288b4cf4">FREE</a>(mode-><a class="code" href="a00019.html#a336e4d433ab15856ab40cdf207ddfd48">name</a>); <a name="l00317"></a>00317 <a name="l00318"></a>00318 <span class="comment">/* Clear the old binding list */</span> <a name="l00319"></a>00319 <a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a> = mode-><a class="code" href="a00019.html#a57efc24f1118014a783ba82a80b73af3">bindings</a>; <a name="l00320"></a>00320 <span class="keywordflow">while</span> (!<a class="code" href="a00047.html#ac3c9da7ac712eacbbad5cc54d7a3477e">TAILQ_EMPTY</a>(<a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>)) { <a name="l00321"></a>00321 bind = <a class="code" href="a00047.html#a7d6894360bd1c41e0e6f6d84998c1362">TAILQ_FIRST</a>(<a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>); <a name="l00322"></a>00322 <a class="code" href="a00047.html#aaae87ca18c28066e1a96221e762d1209">TAILQ_REMOVE</a>(<a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>, bind, <a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>); <a name="l00323"></a>00323 <a class="code" href="a00052.html#ae88e84de75be0b138a19509d288b4cf4">FREE</a>(bind-><a class="code" href="a00003.html#a66527e5582bc56a6bae1f08fa3af55cb" title="Only in use if symbol != NULL.">translated_to</a>); <a name="l00324"></a>00324 <a class="code" href="a00052.html#ae88e84de75be0b138a19509d288b4cf4">FREE</a>(bind-><a class="code" href="a00003.html#a6b2981f10cc6dc9d285d8091e7c55812" title="Command, like in command mode.">command</a>); <a name="l00325"></a>00325 <a class="code" href="a00052.html#ae88e84de75be0b138a19509d288b4cf4">FREE</a>(bind); <a name="l00326"></a>00326 } <a name="l00327"></a>00327 <a class="code" href="a00052.html#ae88e84de75be0b138a19509d288b4cf4">FREE</a>(<a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a>); <a name="l00328"></a>00328 <a class="code" href="a00047.html#a9c7950d61593ab9198524fca81b17ab0">SLIST_REMOVE</a>(&<a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">modes</a>, mode, <a class="code" href="a00019.html" title="The configuration file can contain multiple sets of bindings.">Mode</a>, <a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">modes</a>); <a name="l00329"></a>00329 } <a name="l00330"></a>00330 <a name="l00331"></a>00331 <span class="keyword">struct </span><a class="code" href="a00001.html" title="Holds an assignment for a given window class/title to a specific workspace (see src/config...">Assignment</a> *assign; <a name="l00332"></a>00332 <span class="keywordflow">while</span> (!<a class="code" href="a00047.html#ac3c9da7ac712eacbbad5cc54d7a3477e">TAILQ_EMPTY</a>(&<a class="code" href="a00071.html#af36d2f2cbc5487cf0e9e2d60165b3e89">assignments</a>)) { <a name="l00333"></a>00333 assign = <a class="code" href="a00047.html#a7d6894360bd1c41e0e6f6d84998c1362">TAILQ_FIRST</a>(&<a class="code" href="a00071.html#af36d2f2cbc5487cf0e9e2d60165b3e89">assignments</a>); <a name="l00334"></a>00334 <a class="code" href="a00052.html#ae88e84de75be0b138a19509d288b4cf4">FREE</a>(assign-><a class="code" href="a00001.html#aaf25640d8abe3c02c613fdc54d77878d">windowclass_title</a>); <a name="l00335"></a>00335 <a class="code" href="a00047.html#aaae87ca18c28066e1a96221e762d1209">TAILQ_REMOVE</a>(&<a class="code" href="a00071.html#af36d2f2cbc5487cf0e9e2d60165b3e89">assignments</a>, assign, <a class="code" href="a00071.html#af36d2f2cbc5487cf0e9e2d60165b3e89">assignments</a>); <a name="l00336"></a>00336 <a class="code" href="a00052.html#ae88e84de75be0b138a19509d288b4cf4">FREE</a>(assign); <a name="l00337"></a>00337 } <a name="l00338"></a>00338 <a name="l00339"></a>00339 <span class="comment">/* Clear workspace names */</span> <a name="l00340"></a>00340 <a class="code" href="a00025.html" title="The concept of Workspaces is known from various other window managers.">Workspace</a> *ws; <a name="l00341"></a>00341 <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(ws, <a class="code" href="a00076.html#afb45f3a3a9c66c3e3a5e4d372ae24da7">workspaces</a>, <a class="code" href="a00076.html#afb45f3a3a9c66c3e3a5e4d372ae24da7">workspaces</a>) <a name="l00342"></a>00342 <a class="code" href="a00078.html#a492c5885bad35ce073562238ab5bc72d" title="Sets the name (or just its number) for the given workspace.">workspace_set_name</a>(ws, NULL); <a name="l00343"></a>00343 } <a name="l00344"></a>00344 <a name="l00345"></a>00345 <a class="code" href="a00047.html#a361ac8e88cf066cc4d46d28b54fd3031">SLIST_INIT</a>(&<a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">modes</a>); <a name="l00346"></a>00346 <a name="l00347"></a>00347 <span class="keyword">struct </span><a class="code" href="a00019.html" title="The configuration file can contain multiple sets of bindings.">Mode</a> *default_mode = <a class="code" href="a00077.html#ad475e1b898d9da9b2a8b92e3da51b3dd" title="Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there...">scalloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> <a class="code" href="a00019.html" title="The configuration file can contain multiple sets of bindings.">Mode</a>)); <a name="l00348"></a>00348 default_mode-><a class="code" href="a00019.html#a336e4d433ab15856ab40cdf207ddfd48">name</a> = <a class="code" href="a00077.html#a11822d1f4b182be3fa03d2a5af536e1a" title="Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there...">sstrdup</a>(<span class="stringliteral">"default"</span>); <a name="l00349"></a>00349 default_mode-><a class="code" href="a00019.html#a57efc24f1118014a783ba82a80b73af3">bindings</a> = <a class="code" href="a00077.html#ad475e1b898d9da9b2a8b92e3da51b3dd" title="Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there...">scalloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> bindings_head)); <a name="l00350"></a>00350 <a class="code" href="a00047.html#a449d224023780e46253b83b61e0a50a9">TAILQ_INIT</a>(default_mode-><a class="code" href="a00019.html#a57efc24f1118014a783ba82a80b73af3">bindings</a>); <a name="l00351"></a>00351 <a class="code" href="a00047.html#a48df7439e09a419afabdd1f2f8551e73">SLIST_INSERT_HEAD</a>(&<a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">modes</a>, default_mode, <a class="code" href="a00062.html#a8a9fd888b55140d95a6f0c79a154b02c">modes</a>); <a name="l00352"></a>00352 <a name="l00353"></a>00353 <a class="code" href="a00071.html#afe67646b6ee7ae51b130a59354fe7f49">bindings</a> = default_mode-><a class="code" href="a00019.html#a57efc24f1118014a783ba82a80b73af3">bindings</a>; <a name="l00354"></a>00354 <a name="l00355"></a>00355 <span class="preprocessor">#define REQUIRED_OPTION(name) \</span> <a name="l00356"></a>00356 <span class="preprocessor"> if (config.name == NULL) \</span> <a name="l00357"></a>00357 <span class="preprocessor"> die("You did not specify required configuration option " #name "\n");</span> <a name="l00358"></a>00358 <span class="preprocessor"></span> <a name="l00359"></a>00359 <span class="comment">/* Clear the old config or initialize the data structure */</span> <a name="l00360"></a>00360 memset(&config, 0, <span class="keyword">sizeof</span>(config)); <a name="l00361"></a>00361 <a name="l00362"></a>00362 <span class="comment">/* Initialize default colors */</span> <a name="l00363"></a>00363 <span class="preprocessor">#define INIT_COLOR(x, cborder, cbackground, ctext) \</span> <a name="l00364"></a>00364 <span class="preprocessor"> do { \</span> <a name="l00365"></a>00365 <span class="preprocessor"> x.border = get_colorpixel(conn, cborder); \</span> <a name="l00366"></a>00366 <span class="preprocessor"> x.background = get_colorpixel(conn, cbackground); \</span> <a name="l00367"></a>00367 <span class="preprocessor"> x.text = get_colorpixel(conn, ctext); \</span> <a name="l00368"></a>00368 <span class="preprocessor"> } while (0)</span> <a name="l00369"></a>00369 <span class="preprocessor"></span> <a name="l00370"></a>00370 <a class="code" href="a00062.html#afa93ac77ffba69363be62e7b0e37f11d">INIT_COLOR</a>(config.<a class="code" href="a00010.html#a2cfc8e52ae874b8a76b8103b8da7b520">client</a>.<a class="code" href="a00012.html#a099c67879c7e681a9679a2215b9a5345">focused</a>, <span class="stringliteral">"#4c7899"</span>, <span class="stringliteral">"#285577"</span>, <span class="stringliteral">"#ffffff"</span>); <a name="l00371"></a>00371 <a class="code" href="a00062.html#afa93ac77ffba69363be62e7b0e37f11d">INIT_COLOR</a>(config.<a class="code" href="a00010.html#a2cfc8e52ae874b8a76b8103b8da7b520">client</a>.<a class="code" href="a00012.html#ac0752caef95470dc6e6bf425ee88134f">focused_inactive</a>, <span class="stringliteral">"#333333"</span>, <span class="stringliteral">"#5f676a"</span>, <span class="stringliteral">"#ffffff"</span>); <a name="l00372"></a>00372 <a class="code" href="a00062.html#afa93ac77ffba69363be62e7b0e37f11d">INIT_COLOR</a>(config.<a class="code" href="a00010.html#a2cfc8e52ae874b8a76b8103b8da7b520">client</a>.<a class="code" href="a00012.html#a5b24b86010b37d8771adae7df82f4c04">unfocused</a>, <span class="stringliteral">"#333333"</span>, <span class="stringliteral">"#222222"</span>, <span class="stringliteral">"#888888"</span>); <a name="l00373"></a>00373 <a class="code" href="a00062.html#afa93ac77ffba69363be62e7b0e37f11d">INIT_COLOR</a>(config.<a class="code" href="a00010.html#a2cfc8e52ae874b8a76b8103b8da7b520">client</a>.<a class="code" href="a00012.html#aa99761c3565876674356bf2cb5f62856">urgent</a>, <span class="stringliteral">"#2f343a"</span>, <span class="stringliteral">"#900000"</span>, <span class="stringliteral">"#ffffff"</span>); <a name="l00374"></a>00374 <a class="code" href="a00062.html#afa93ac77ffba69363be62e7b0e37f11d">INIT_COLOR</a>(config.<a class="code" href="a00010.html#a87797dfb71243a11161231d2fdf3ecdb">bar</a>.<a class="code" href="a00011.html#a53350b6b2d0d985dadf8bbade54237e7">focused</a>, <span class="stringliteral">"#4c7899"</span>, <span class="stringliteral">"#285577"</span>, <span class="stringliteral">"#ffffff"</span>); <a name="l00375"></a>00375 <a class="code" href="a00062.html#afa93ac77ffba69363be62e7b0e37f11d">INIT_COLOR</a>(config.<a class="code" href="a00010.html#a87797dfb71243a11161231d2fdf3ecdb">bar</a>.<a class="code" href="a00011.html#a99f68b3648d5b17e92e02f29c5eab9ca">unfocused</a>, <span class="stringliteral">"#333333"</span>, <span class="stringliteral">"#222222"</span>, <span class="stringliteral">"#888888"</span>); <a name="l00376"></a>00376 <a class="code" href="a00062.html#afa93ac77ffba69363be62e7b0e37f11d">INIT_COLOR</a>(config.<a class="code" href="a00010.html#a87797dfb71243a11161231d2fdf3ecdb">bar</a>.<a class="code" href="a00011.html#acec0f35d252f351505156ead6757f6bb">urgent</a>, <span class="stringliteral">"#2f343a"</span>, <span class="stringliteral">"#900000"</span>, <span class="stringliteral">"#ffffff"</span>); <a name="l00377"></a>00377 <a name="l00378"></a>00378 <a class="code" href="a00062.html#a6f3a92013cf7e1ece6139b05a43a2c95">parse_configuration</a>(override_configpath); <a name="l00379"></a>00379 <a name="l00380"></a>00380 <span class="keywordflow">if</span> (reload) { <a name="l00381"></a>00381 <a class="code" href="a00062.html#a0ee8ffa5c11aeb96126b36171da84adc" title="Translates keysymbols to keycodes for all bindings which use keysyms.">translate_keysyms</a>(); <a name="l00382"></a>00382 <a class="code" href="a00062.html#a1741cf749eb2243cca453355d3f6879b" title="Grab the bound keys (tell X to send us keypress events for those keycodes).">grab_all_keys</a>(conn, <span class="keyword">false</span>); <a name="l00383"></a>00383 } <a name="l00384"></a>00384 <a name="l00385"></a>00385 <a class="code" href="a00062.html#ae09f26b7018670246503bd977bc53a10">REQUIRED_OPTION</a>(font); <a name="l00386"></a>00386 <a name="l00387"></a>00387 <span class="comment">/* Set an empty name for every workspace which got no name */</span> <a name="l00388"></a>00388 <a class="code" href="a00025.html" title="The concept of Workspaces is known from various other window managers.">Workspace</a> *ws; <a name="l00389"></a>00389 <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(ws, <a class="code" href="a00076.html#afb45f3a3a9c66c3e3a5e4d372ae24da7">workspaces</a>, <a class="code" href="a00076.html#afb45f3a3a9c66c3e3a5e4d372ae24da7">workspaces</a>) { <a name="l00390"></a>00390 <span class="keywordflow">if</span> (ws-><a class="code" href="a00025.html#a2db20d0a3a8866278611898710445017" title="Name of the workspace (in UCS-2).">name</a> != NULL) { <a name="l00391"></a>00391 <span class="comment">/* If the font was not specified when the workspace name</span> <a name="l00392"></a>00392 <span class="comment"> * was loaded, we need to predict the text width now */</span> <a name="l00393"></a>00393 <span class="keywordflow">if</span> (ws-><a class="code" href="a00025.html#ad7c51613ba7339af44071f450af5f37d" title="Width of the workspace’s name (in pixels) rendered in config.font.">text_width</a> == 0) <a name="l00394"></a>00394 ws-><a class="code" href="a00025.html#ad7c51613ba7339af44071f450af5f37d" title="Width of the workspace’s name (in pixels) rendered in config.font.">text_width</a> = <a class="code" href="a00079.html#a01397b2251980ca02d24194293fc79d0" title="Calculate the width of the given text (16-bit characters, UCS) with given real length...">predict_text_width</a>(<a class="code" href="a00071.html#ada13c42121d64521629e06e7a5e1db16">global_conn</a>, <a name="l00395"></a>00395 config.<a class="code" href="a00010.html#aff568f0d5ca7a51971f4c3006a842019">font</a>, ws-><a class="code" href="a00025.html#a2db20d0a3a8866278611898710445017" title="Name of the workspace (in UCS-2).">name</a>, ws-><a class="code" href="a00025.html#a190c6f4026f0bff8b0d49340823fc1e1" title="Length of the workspace’s name (in glyphs).">name_len</a>); <a name="l00396"></a>00396 <span class="keywordflow">continue</span>; <a name="l00397"></a>00397 } <a name="l00398"></a>00398 <a name="l00399"></a>00399 <a class="code" href="a00078.html#a492c5885bad35ce073562238ab5bc72d" title="Sets the name (or just its number) for the given workspace.">workspace_set_name</a>(ws, NULL); <a name="l00400"></a>00400 } <a name="l00401"></a>00401 } </pre></div></div> <hr class="footer"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2-20100208 </small></address> </body> </html>