Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > c67c6057ffd14254a26624517a2352e6 > files > 608

i3-doc-3.e-3.bf1.fc14.noarch.rpm

<!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/util.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&nbsp;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;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&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<h1>src/util.c</h1><a href="a00077.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 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"> * util.c: Utility functions, which can be useful everywhere.</span>
<a name="l00011"></a>00011 <span class="comment"> *</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;sys/wait.h&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;stdarg.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;iconv.h&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#if defined(__OpenBSD__)</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sys/cdefs.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#endif</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;xcb/xcb_icccm.h&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#include &quot;<a class="code" href="a00041.html">i3.h</a>&quot;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;<a class="code" href="a00036.html">data.h</a>&quot;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;<a class="code" href="a00051.html">table.h</a>&quot;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;<a class="code" href="a00043.html">layout.h</a>&quot;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &quot;<a class="code" href="a00052.html">util.h</a>&quot;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &quot;<a class="code" href="a00054.html">xcb.h</a>&quot;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;<a class="code" href="a00032.html">client.h</a>&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;<a class="code" href="a00044.html">log.h</a>&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;<a class="code" href="a00038.html">ewmh.h</a>&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;<a class="code" href="a00046.html">manage.h</a>&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;<a class="code" href="a00053.html">workspace.h</a>&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;<a class="code" href="a00042.html">ipc.h</a>&quot;</span>
<a name="l00039"></a>00039 
<a name="l00040"></a><a class="code" href="a00077.html#afd57bdc78393cf2e79ad556e7b973204">00040</a> <span class="keyword">static</span> iconv_t <a class="code" href="a00077.html#afd57bdc78393cf2e79ad556e7b973204">conversion_descriptor</a> = 0;
<a name="l00041"></a><a class="code" href="a00052.html#a38dffc58d761d720f7c63d35f2efd71d">00041</a> <span class="keyword">struct </span>keyvalue_table_head <a class="code" href="a00077.html#a38dffc58d761d720f7c63d35f2efd71d">by_parent</a> = <a class="code" href="a00047.html#ac269df7d4126ed9885156cbad2cbf8af">TAILQ_HEAD_INITIALIZER</a>(<a class="code" href="a00077.html#a38dffc58d761d720f7c63d35f2efd71d">by_parent</a>);
<a name="l00042"></a><a class="code" href="a00052.html#aadfb9c6f265623f83355191df37c86c8">00042</a> <span class="keyword">struct </span>keyvalue_table_head <a class="code" href="a00077.html#aadfb9c6f265623f83355191df37c86c8">by_child</a> = <a class="code" href="a00047.html#ac269df7d4126ed9885156cbad2cbf8af">TAILQ_HEAD_INITIALIZER</a>(<a class="code" href="a00077.html#aadfb9c6f265623f83355191df37c86c8">by_child</a>);
<a name="l00043"></a>00043 
<a name="l00044"></a><a class="code" href="a00052.html#abd8bbcfabb3ddef2ccaafb9928a37b95">00044</a> <span class="keywordtype">int</span> <a class="code" href="a00077.html#abd8bbcfabb3ddef2ccaafb9928a37b95">min</a>(<span class="keywordtype">int</span> a, <span class="keywordtype">int</span> b) {
<a name="l00045"></a>00045         <span class="keywordflow">return</span> (a &lt; b ? a : b);
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 
<a name="l00048"></a><a class="code" href="a00052.html#af082905f7eac6d03e92015146bbc1925">00048</a> <span class="keywordtype">int</span> <a class="code" href="a00077.html#af082905f7eac6d03e92015146bbc1925">max</a>(<span class="keywordtype">int</span> a, <span class="keywordtype">int</span> b) {
<a name="l00049"></a>00049         <span class="keywordflow">return</span> (a &gt; b ? a : b);
<a name="l00050"></a>00050 }
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 <span class="comment">/*</span>
<a name="l00053"></a>00053 <span class="comment"> * Updates *destination with new_value and returns true if it was changed or false</span>
<a name="l00054"></a>00054 <span class="comment"> * if it was the same</span>
<a name="l00055"></a>00055 <span class="comment"> *</span>
<a name="l00056"></a>00056 <span class="comment"> */</span>
<a name="l00057"></a><a class="code" href="a00052.html#a4dfa7907c5f327e6383b32d6e8acde8f">00057</a> <span class="keywordtype">bool</span> <a class="code" href="a00077.html#a4dfa7907c5f327e6383b32d6e8acde8f" title="Updates *destination with new_value and returns true if it was changed or false if...">update_if_necessary</a>(uint32_t *destination, <span class="keyword">const</span> uint32_t new_value) {
<a name="l00058"></a>00058         uint32_t old_value = *destination;
<a name="l00059"></a>00059 
<a name="l00060"></a>00060         <span class="keywordflow">return</span> ((*destination = new_value) != old_value);
<a name="l00061"></a>00061 }
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 <span class="comment">/*</span>
<a name="l00064"></a>00064 <span class="comment"> * The s* functions (safe) are wrappers around malloc, strdup, …, which exits if one of</span>
<a name="l00065"></a>00065 <span class="comment"> * the called functions returns NULL, meaning that there is no more memory available</span>
<a name="l00066"></a>00066 <span class="comment"> *</span>
<a name="l00067"></a>00067 <span class="comment"> */</span>
<a name="l00068"></a><a class="code" href="a00052.html#a46c23cb2833f4b674f5cfc977f16b990">00068</a> <span class="keywordtype">void</span> *<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="keywordtype">size_t</span> size) {
<a name="l00069"></a>00069         <span class="keywordtype">void</span> *result = malloc(size);
<a name="l00070"></a>00070         <a class="code" href="a00052.html#ad484926a44f04ac0640b81561442091a">exit_if_null</a>(result, <span class="stringliteral">&quot;Error: out of memory (malloc(%zd))\n&quot;</span>, size);
<a name="l00071"></a>00071         <span class="keywordflow">return</span> result;
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073 
<a name="l00074"></a><a class="code" href="a00052.html#ad475e1b898d9da9b2a8b92e3da51b3dd">00074</a> <span class="keywordtype">void</span> *<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="keywordtype">size_t</span> size) {
<a name="l00075"></a>00075         <span class="keywordtype">void</span> *result = calloc(size, 1);
<a name="l00076"></a>00076         <a class="code" href="a00052.html#ad484926a44f04ac0640b81561442091a">exit_if_null</a>(result, <span class="stringliteral">&quot;Error: out of memory (calloc(%zd))\n&quot;</span>, size);
<a name="l00077"></a>00077         <span class="keywordflow">return</span> result;
<a name="l00078"></a>00078 }
<a name="l00079"></a>00079 
<a name="l00080"></a><a class="code" href="a00052.html#a11822d1f4b182be3fa03d2a5af536e1a">00080</a> <span class="keywordtype">char</span> *<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="keyword">const</span> <span class="keywordtype">char</span> *str) {
<a name="l00081"></a>00081         <span class="keywordtype">char</span> *result = strdup(str);
<a name="l00082"></a>00082         <a class="code" href="a00052.html#ad484926a44f04ac0640b81561442091a">exit_if_null</a>(result, <span class="stringliteral">&quot;Error: out of memory (strdup())\n&quot;</span>);
<a name="l00083"></a>00083         <span class="keywordflow">return</span> result;
<a name="l00084"></a>00084 }
<a name="l00085"></a>00085 
<a name="l00086"></a>00086 <span class="comment">/*</span>
<a name="l00087"></a>00087 <span class="comment"> * The table_* functions emulate the behaviour of libxcb-wm, which in libxcb 0.3.4 suddenly</span>
<a name="l00088"></a>00088 <span class="comment"> * vanished. Great.</span>
<a name="l00089"></a>00089 <span class="comment"> *</span>
<a name="l00090"></a>00090 <span class="comment"> */</span>
<a name="l00091"></a><a class="code" href="a00052.html#a387447a095debe780790788f18e88d6e">00091</a> <span class="keywordtype">bool</span> <a class="code" href="a00077.html#a387447a095debe780790788f18e88d6e" title="Inserts an element into the given keyvalue-table using the given key.">table_put</a>(<span class="keyword">struct</span> keyvalue_table_head *head, uint32_t key, <span class="keywordtype">void</span> *value) {
<a name="l00092"></a>00092         <span class="keyword">struct </span><a class="code" href="a00018.html" title="Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4 suddenly vanished...">keyvalue_element</a> *element = <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="a00018.html" title="Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4 suddenly vanished...">keyvalue_element</a>));
<a name="l00093"></a>00093         element-&gt;<a class="code" href="a00018.html#acb452c86738581ce16003fb046aa43c2">key</a> = key;
<a name="l00094"></a>00094         element-&gt;<a class="code" href="a00018.html#ab527ef4dfaf72f281e95cab71a5e5e96">value</a> = value;
<a name="l00095"></a>00095 
<a name="l00096"></a>00096         <a class="code" href="a00047.html#a512bee16b46f601078c96c776d2648c3">TAILQ_INSERT_TAIL</a>(head, element, elements);
<a name="l00097"></a>00097         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099 
<a name="l00100"></a><a class="code" href="a00052.html#a325edcce10c699e46d7638d4361599e7">00100</a> <span class="keywordtype">void</span> *<a class="code" href="a00077.html#a325edcce10c699e46d7638d4361599e7" title="Removes the element from the given keyvalue-table with the given key and returns...">table_remove</a>(<span class="keyword">struct</span> keyvalue_table_head *head, uint32_t <a class="code" href="a00018.html#acb452c86738581ce16003fb046aa43c2">key</a>) {
<a name="l00101"></a>00101         <span class="keyword">struct </span><a class="code" href="a00018.html" title="Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4 suddenly vanished...">keyvalue_element</a> *element;
<a name="l00102"></a>00102 
<a name="l00103"></a>00103         <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(element, head, elements)
<a name="l00104"></a>00104                 <span class="keywordflow">if</span> (element-&gt;<a class="code" href="a00018.html#acb452c86738581ce16003fb046aa43c2">key</a> == key) {
<a name="l00105"></a>00105                         <span class="keywordtype">void</span> *<a class="code" href="a00018.html#ab527ef4dfaf72f281e95cab71a5e5e96">value</a> = element-&gt;<a class="code" href="a00018.html#ab527ef4dfaf72f281e95cab71a5e5e96">value</a>;
<a name="l00106"></a>00106                         <a class="code" href="a00047.html#aaae87ca18c28066e1a96221e762d1209">TAILQ_REMOVE</a>(head, element, elements);
<a name="l00107"></a>00107                         free(element);
<a name="l00108"></a>00108                         <span class="keywordflow">return</span> value;
<a name="l00109"></a>00109                 }
<a name="l00110"></a>00110 
<a name="l00111"></a>00111         <span class="keywordflow">return</span> NULL;
<a name="l00112"></a>00112 }
<a name="l00113"></a>00113 
<a name="l00114"></a><a class="code" href="a00052.html#ae1529a1d81e2457f9a2402eda35735d7">00114</a> <span class="keywordtype">void</span> *<a class="code" href="a00077.html#ae1529a1d81e2457f9a2402eda35735d7" title="Returns the value of the element of the given keyvalue-table with the given key.">table_get</a>(<span class="keyword">struct</span> keyvalue_table_head *head, uint32_t <a class="code" href="a00018.html#acb452c86738581ce16003fb046aa43c2">key</a>) {
<a name="l00115"></a>00115         <span class="keyword">struct </span><a class="code" href="a00018.html" title="Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4 suddenly vanished...">keyvalue_element</a> *element;
<a name="l00116"></a>00116 
<a name="l00117"></a>00117         <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(element, head, elements)
<a name="l00118"></a>00118                 <span class="keywordflow">if</span> (element-&gt;<a class="code" href="a00018.html#acb452c86738581ce16003fb046aa43c2">key</a> == key)
<a name="l00119"></a>00119                         <span class="keywordflow">return</span> element-&gt;<a class="code" href="a00018.html#ab527ef4dfaf72f281e95cab71a5e5e96">value</a>;
<a name="l00120"></a>00120 
<a name="l00121"></a>00121         <span class="keywordflow">return</span> NULL;
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123 
<a name="l00124"></a>00124 <span class="comment">/*</span>
<a name="l00125"></a>00125 <span class="comment"> * Starts the given application by passing it through a shell. We use double fork</span>
<a name="l00126"></a>00126 <span class="comment"> * to avoid zombie processes. As the started application’s parent exits (immediately),</span>
<a name="l00127"></a>00127 <span class="comment"> * the application is reparented to init (process-id 1), which correctly handles</span>
<a name="l00128"></a>00128 <span class="comment"> * childs, so we don’t have to do it :-).</span>
<a name="l00129"></a>00129 <span class="comment"> *</span>
<a name="l00130"></a>00130 <span class="comment"> * The shell is determined by looking for the SHELL environment variable. If it</span>
<a name="l00131"></a>00131 <span class="comment"> * does not exist, /bin/sh is used.</span>
<a name="l00132"></a>00132 <span class="comment"> *</span>
<a name="l00133"></a>00133 <span class="comment"> */</span>
<a name="l00134"></a><a class="code" href="a00052.html#a4a1b0dbf1f2e37a0ad5a0f6cc786225c">00134</a> <span class="keywordtype">void</span> <a class="code" href="a00077.html#a4a1b0dbf1f2e37a0ad5a0f6cc786225c" title="Starts the given application by passing it through a shell.">start_application</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *command) {
<a name="l00135"></a>00135         <span class="keywordflow">if</span> (fork() == 0) {
<a name="l00136"></a>00136                 <span class="comment">/* Child process */</span>
<a name="l00137"></a>00137                 <span class="keywordflow">if</span> (fork() == 0) {
<a name="l00138"></a>00138                         <span class="comment">/* Stores the path of the shell */</span>
<a name="l00139"></a>00139                         <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *shell = NULL;
<a name="l00140"></a>00140 
<a name="l00141"></a>00141                         <span class="keywordflow">if</span> (shell == NULL)
<a name="l00142"></a>00142                                 <span class="keywordflow">if</span> ((shell = getenv(<span class="stringliteral">&quot;SHELL&quot;</span>)) == NULL)
<a name="l00143"></a>00143                                         shell = <span class="stringliteral">&quot;/bin/sh&quot;</span>;
<a name="l00144"></a>00144 
<a name="l00145"></a>00145                         <span class="comment">/* This is the child */</span>
<a name="l00146"></a>00146                         execl(shell, shell, <span class="stringliteral">&quot;-c&quot;</span>, command, (<span class="keywordtype">void</span>*)NULL);
<a name="l00147"></a>00147                         <span class="comment">/* not reached */</span>
<a name="l00148"></a>00148                 }
<a name="l00149"></a>00149                 exit(0);
<a name="l00150"></a>00150         }
<a name="l00151"></a>00151         wait(0);
<a name="l00152"></a>00152 }
<a name="l00153"></a>00153 
<a name="l00154"></a>00154 <span class="comment">/*</span>
<a name="l00155"></a>00155 <span class="comment"> * Checks a generic cookie for errors and quits with the given message if there</span>
<a name="l00156"></a>00156 <span class="comment"> * was an error.</span>
<a name="l00157"></a>00157 <span class="comment"> *</span>
<a name="l00158"></a>00158 <span class="comment"> */</span>
<a name="l00159"></a><a class="code" href="a00052.html#ae8ee4cede01d9a00cbeaffbc5f096f8d">00159</a> <span class="keywordtype">void</span> <a class="code" href="a00077.html#ae8ee4cede01d9a00cbeaffbc5f096f8d" title="Checks a generic cookie for errors and quits with the given message if there was...">check_error</a>(xcb_connection_t *conn, xcb_void_cookie_t cookie, <span class="keywordtype">char</span> *err_message) {
<a name="l00160"></a>00160         xcb_generic_error_t *error = xcb_request_check(conn, cookie);
<a name="l00161"></a>00161         <span class="keywordflow">if</span> (error != NULL) {
<a name="l00162"></a>00162                 fprintf(stderr, <span class="stringliteral">&quot;ERROR: %s (X error %d)\n&quot;</span>, err_message , error-&gt;error_code);
<a name="l00163"></a>00163                 xcb_disconnect(conn);
<a name="l00164"></a>00164                 exit(-1);
<a name="l00165"></a>00165         }
<a name="l00166"></a>00166 }
<a name="l00167"></a>00167 
<a name="l00168"></a>00168 <span class="comment">/*</span>
<a name="l00169"></a>00169 <span class="comment"> * Converts the given string to UCS-2 big endian for use with</span>
<a name="l00170"></a>00170 <span class="comment"> * xcb_image_text_16(). The amount of real glyphs is stored in real_strlen,</span>
<a name="l00171"></a>00171 <span class="comment"> * a buffer containing the UCS-2 encoded string (16 bit per glyph) is</span>
<a name="l00172"></a>00172 <span class="comment"> * returned. It has to be freed when done.</span>
<a name="l00173"></a>00173 <span class="comment"> *</span>
<a name="l00174"></a>00174 <span class="comment"> */</span>
<a name="l00175"></a><a class="code" href="a00052.html#a1d926a6371d3d87f2dd85c1a27d83f4b">00175</a> <span class="keywordtype">char</span> *<a class="code" href="a00077.html#a1d926a6371d3d87f2dd85c1a27d83f4b" title="Converts the given string to UCS-2 big endian for use with xcb_image_text_16().">convert_utf8_to_ucs2</a>(<span class="keywordtype">char</span> *input, <span class="keywordtype">int</span> *real_strlen) {
<a name="l00176"></a>00176         <span class="keywordtype">size_t</span> input_size = strlen(input) + 1;
<a name="l00177"></a>00177         <span class="comment">/* UCS-2 consumes exactly two bytes for each glyph */</span>
<a name="l00178"></a>00178         <span class="keywordtype">int</span> buffer_size = input_size * 2;
<a name="l00179"></a>00179 
<a name="l00180"></a>00180         <span class="keywordtype">char</span> *buffer = <a class="code" href="a00077.html#a46c23cb2833f4b674f5cfc977f16b990" title="Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there...">smalloc</a>(buffer_size);
<a name="l00181"></a>00181         <span class="keywordtype">size_t</span> output_size = buffer_size;
<a name="l00182"></a>00182         <span class="comment">/* We need to use an additional pointer, because iconv() modifies it */</span>
<a name="l00183"></a>00183         <span class="keywordtype">char</span> *output = buffer;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185         <span class="comment">/* We convert the input into UCS-2 big endian */</span>
<a name="l00186"></a>00186         <span class="keywordflow">if</span> (<a class="code" href="a00077.html#afd57bdc78393cf2e79ad556e7b973204">conversion_descriptor</a> == 0) {
<a name="l00187"></a>00187                 <a class="code" href="a00077.html#afd57bdc78393cf2e79ad556e7b973204">conversion_descriptor</a> = iconv_open(<span class="stringliteral">&quot;UCS-2BE&quot;</span>, <span class="stringliteral">&quot;UTF-8&quot;</span>);
<a name="l00188"></a>00188                 <span class="keywordflow">if</span> (<a class="code" href="a00077.html#afd57bdc78393cf2e79ad556e7b973204">conversion_descriptor</a> == 0) {
<a name="l00189"></a>00189                         fprintf(stderr, <span class="stringliteral">&quot;error opening the conversion context\n&quot;</span>);
<a name="l00190"></a>00190                         exit(1);
<a name="l00191"></a>00191                 }
<a name="l00192"></a>00192         }
<a name="l00193"></a>00193 
<a name="l00194"></a>00194         <span class="comment">/* Get the conversion descriptor back to original state */</span>
<a name="l00195"></a>00195         iconv(<a class="code" href="a00077.html#afd57bdc78393cf2e79ad556e7b973204">conversion_descriptor</a>, NULL, NULL, NULL, NULL);
<a name="l00196"></a>00196 
<a name="l00197"></a>00197         <span class="comment">/* Convert our text */</span>
<a name="l00198"></a>00198         <span class="keywordtype">int</span> rc = iconv(<a class="code" href="a00077.html#afd57bdc78393cf2e79ad556e7b973204">conversion_descriptor</a>, (<span class="keywordtype">void</span>*)&amp;input, &amp;input_size, &amp;output, &amp;output_size);
<a name="l00199"></a>00199         <span class="keywordflow">if</span> (rc == (<span class="keywordtype">size_t</span>)-1) {
<a name="l00200"></a>00200                 perror(<span class="stringliteral">&quot;Converting to UCS-2 failed&quot;</span>);
<a name="l00201"></a>00201                 <span class="keywordflow">if</span> (real_strlen != NULL)
<a name="l00202"></a>00202                         *real_strlen = 0;
<a name="l00203"></a>00203                 <span class="keywordflow">return</span> NULL;
<a name="l00204"></a>00204         }
<a name="l00205"></a>00205 
<a name="l00206"></a>00206         <span class="keywordflow">if</span> (real_strlen != NULL)
<a name="l00207"></a>00207                 *real_strlen = ((buffer_size - output_size) / 2) - 1;
<a name="l00208"></a>00208 
<a name="l00209"></a>00209         <span class="keywordflow">return</span> buffer;
<a name="l00210"></a>00210 }
<a name="l00211"></a>00211 
<a name="l00212"></a>00212 <span class="comment">/*</span>
<a name="l00213"></a>00213 <span class="comment"> * Returns the client which comes next in focus stack (= was selected before) for</span>
<a name="l00214"></a>00214 <span class="comment"> * the given container, optionally excluding the given client.</span>
<a name="l00215"></a>00215 <span class="comment"> *</span>
<a name="l00216"></a>00216 <span class="comment"> */</span>
<a name="l00217"></a><a class="code" href="a00052.html#ad5a21e1f5f7065c1997717c13559907a">00217</a> <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *<a class="code" href="a00077.html#ad5a21e1f5f7065c1997717c13559907a" title="Returns the client which comes next in focus stack (= was selected before) for the...">get_last_focused_client</a>(xcb_connection_t *conn, <a class="code" href="a00013.html" title="A container is either in default, stacking or tabbed mode.">Container</a> *container, <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *exclude) {
<a name="l00218"></a>00218         <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *current;
<a name="l00219"></a>00219         <a class="code" href="a00047.html#a05db87878125c27e3060dd641aa3b0f4">SLIST_FOREACH</a>(current, &amp;(container-&gt;<a class="code" href="a00013.html#a98ed501e1088ccf2e7c75399ab7e6031">workspace</a>-&gt;focus_stack), focus_clients)
<a name="l00220"></a>00220                 <span class="keywordflow">if</span> ((current-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a> == container) &amp;&amp; ((exclude == NULL) || (current != exclude)))
<a name="l00221"></a>00221                         <span class="keywordflow">return</span> current;
<a name="l00222"></a>00222         <span class="keywordflow">return</span> NULL;
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 
<a name="l00225"></a>00225 
<a name="l00226"></a>00226 <span class="comment">/*</span>
<a name="l00227"></a>00227 <span class="comment"> * Sets the given client as focused by updating the data structures correctly,</span>
<a name="l00228"></a>00228 <span class="comment"> * updating the X input focus and finally re-decorating both windows (to signalize</span>
<a name="l00229"></a>00229 <span class="comment"> * the user the new focus situation)</span>
<a name="l00230"></a>00230 <span class="comment"> *</span>
<a name="l00231"></a>00231 <span class="comment"> */</span>
<a name="l00232"></a><a class="code" href="a00052.html#a323dcf30475bb3bf165100e74d225b48">00232</a> <span class="keywordtype">void</span> <a class="code" href="a00077.html#a323dcf30475bb3bf165100e74d225b48" title="Sets the given client as focused by updating the data structures correctly, updating...">set_focus</a>(xcb_connection_t *conn, <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *client, <span class="keywordtype">bool</span> set_anyways) {
<a name="l00233"></a>00233         <span class="comment">/* The dock window cannot be focused, but enter notifies are still handled correctly */</span>
<a name="l00234"></a>00234         <span class="keywordflow">if</span> (client-&gt;<a class="code" href="a00007.html#a994b0c5a9eb35e42f04a0b845a3166ef" title="If a client is set as a dock, it is placed at the very bottom of the screen and its...">dock</a>)
<a name="l00235"></a>00235                 <span class="keywordflow">return</span>;
<a name="l00236"></a>00236 
<a name="l00237"></a>00237         <span class="comment">/* Store the old client */</span>
<a name="l00238"></a>00238         <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *old_client = <a class="code" href="a00047.html#a91bac7d0d32e3ec56bc579ace45ed8cd">SLIST_FIRST</a>(&amp;(<a class="code" href="a00076.html#a6dc99dff7063221c1096561951c0386b">c_ws</a>-&gt;focus_stack));
<a name="l00239"></a>00239 
<a name="l00240"></a>00240         <span class="comment">/* Check if the focus needs to be changed at all */</span>
<a name="l00241"></a>00241         <span class="keywordflow">if</span> (!set_anyways &amp;&amp; (old_client == client))
<a name="l00242"></a>00242                 <span class="keywordflow">return</span>;
<a name="l00243"></a>00243 
<a name="l00244"></a>00244         <span class="comment">/* Store current_row/current_col */</span>
<a name="l00245"></a>00245         <a class="code" href="a00076.html#a6dc99dff7063221c1096561951c0386b">c_ws</a>-&gt;<a class="code" href="a00025.html#a86fefbdc838f2b5593ea2521378e4ddd" title="These are stored here only while this workspace is _not_ shown (see show_workspace())...">current_row</a> = <a class="code" href="a00076.html#a40ba377d6a3a574ff03b859bc7cdd4b0">current_row</a>;
<a name="l00246"></a>00246         <a class="code" href="a00076.html#a6dc99dff7063221c1096561951c0386b">c_ws</a>-&gt;<a class="code" href="a00025.html#ab683091dfe46963b2dd0761e8e5f9e16" title="These are stored here only while this workspace is _not_ shown (see show_workspace())...">current_col</a> = <a class="code" href="a00076.html#a5f839b3ac61c0771c9f8fbef974afe76">current_col</a>;
<a name="l00247"></a>00247         <a class="code" href="a00076.html#a6dc99dff7063221c1096561951c0386b">c_ws</a> = client-&gt;<a class="code" href="a00007.html#ab9573ba898dbd1932f5200be5eb2a990" title="Because dock clients don’t have a container, we have this workspace-backpointer...">workspace</a>;
<a name="l00248"></a>00248         <a class="code" href="a00065.html#ae40835a49409f87f53ad4f7449b19b53" title="Updates _NET_CURRENT_DESKTOP with the current desktop number.">ewmh_update_current_desktop</a>();
<a name="l00249"></a>00249         <span class="comment">/* Load current_col/current_row if we switch to a client without a container */</span>
<a name="l00250"></a>00250         <a class="code" href="a00076.html#a5f839b3ac61c0771c9f8fbef974afe76">current_col</a> = <a class="code" href="a00076.html#a6dc99dff7063221c1096561951c0386b">c_ws</a>-&gt;<a class="code" href="a00025.html#ab683091dfe46963b2dd0761e8e5f9e16" title="These are stored here only while this workspace is _not_ shown (see show_workspace())...">current_col</a>;
<a name="l00251"></a>00251         <a class="code" href="a00076.html#a40ba377d6a3a574ff03b859bc7cdd4b0">current_row</a> = <a class="code" href="a00076.html#a6dc99dff7063221c1096561951c0386b">c_ws</a>-&gt;<a class="code" href="a00025.html#a86fefbdc838f2b5593ea2521378e4ddd" title="These are stored here only while this workspace is _not_ shown (see show_workspace())...">current_row</a>;
<a name="l00252"></a>00252 
<a name="l00253"></a>00253         <span class="comment">/* Update container */</span>
<a name="l00254"></a>00254         <span class="keywordflow">if</span> (client-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a> != NULL) {
<a name="l00255"></a>00255                 client-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a>-&gt;<a class="code" href="a00013.html#a82d910506b0d788a92ebeeb1d82da75b">currently_focused</a> = client;
<a name="l00256"></a>00256 
<a name="l00257"></a>00257                 <a class="code" href="a00076.html#a5f839b3ac61c0771c9f8fbef974afe76">current_col</a> = client-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a>-&gt;<a class="code" href="a00013.html#ad20f57a89cdcc15b1e656c67d7b4861a">col</a>;
<a name="l00258"></a>00258                 <a class="code" href="a00076.html#a40ba377d6a3a574ff03b859bc7cdd4b0">current_row</a> = client-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a>-&gt;<a class="code" href="a00013.html#a4fefa5b1b97f096cbee9cd24cc3d6c34">row</a>;
<a name="l00259"></a>00259         }
<a name="l00260"></a>00260 
<a name="l00261"></a>00261         <a class="code" href="a00032.html#ad0346070ecde80a2181a4b87b533bea3" title="Pretty-prints the client’s information into the logfile.">CLIENT_LOG</a>(client);
<a name="l00262"></a>00262         <span class="comment">/* Set focus to the entered window, and flush xcb buffer immediately */</span>
<a name="l00263"></a>00263         xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, client-&gt;<a class="code" href="a00007.html#afba312b946fa74727ce619a33f8f28aa" title="The client’s window.">child</a>, XCB_CURRENT_TIME);
<a name="l00264"></a>00264         <a class="code" href="a00065.html#a07da16d476a61d9ef63f31de1dc84700" title="Updates _NET_ACTIVE_WINDOW with the currently focused window.">ewmh_update_active_window</a>(client-&gt;<a class="code" href="a00007.html#afba312b946fa74727ce619a33f8f28aa" title="The client’s window.">child</a>);
<a name="l00265"></a>00265         <span class="comment">//xcb_warp_pointer(conn, XCB_NONE, client-&gt;child, 0, 0, 0, 0, 10, 10);</span>
<a name="l00266"></a>00266 
<a name="l00267"></a>00267         <span class="keywordflow">if</span> (client-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a> != NULL) {
<a name="l00268"></a>00268                 <span class="comment">/* Get the client which was last focused in this particular container, it may be a different</span>
<a name="l00269"></a>00269 <span class="comment">                   one than old_client */</span>
<a name="l00270"></a>00270                 <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *last_focused = <a class="code" href="a00077.html#ad5a21e1f5f7065c1997717c13559907a" title="Returns the client which comes next in focus stack (= was selected before) for the...">get_last_focused_client</a>(conn, client-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a>, NULL);
<a name="l00271"></a>00271 
<a name="l00272"></a>00272                 <span class="comment">/* In stacking containers, raise the client in respect to the one which was focused before */</span>
<a name="l00273"></a>00273                 <span class="keywordflow">if</span> ((client-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a>-&gt;<a class="code" href="a00013.html#ac094306ab77e360742aba04d7cbd0fe6">mode</a> == MODE_STACK || client-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a>-&gt;<a class="code" href="a00013.html#ac094306ab77e360742aba04d7cbd0fe6">mode</a> == MODE_TABBED) &amp;&amp;
<a name="l00274"></a>00274                     client-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a>-&gt;<a class="code" href="a00013.html#a98ed501e1088ccf2e7c75399ab7e6031">workspace</a>-&gt;<a class="code" href="a00025.html#a918ace3a3d2f03c58ec8fa05ac97275e" title="the client who is started in fullscreen mode on this workspace, NULL if there is...">fullscreen_client</a> == NULL) {
<a name="l00275"></a>00275                         <span class="comment">/* We need to get the client again, this time excluding the current client, because</span>
<a name="l00276"></a>00276 <span class="comment">                         * we might have just gone into stacking mode and need to raise */</span>
<a name="l00277"></a>00277                         <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *last_focused = <a class="code" href="a00077.html#ad5a21e1f5f7065c1997717c13559907a" title="Returns the client which comes next in focus stack (= was selected before) for the...">get_last_focused_client</a>(conn, client-&gt;<a class="code" href="a00007.html#a022927d41b4140a623f72fa360c46a17" title="Backpointer.">container</a>, client);
<a name="l00278"></a>00278 
<a name="l00279"></a>00279                         <span class="keywordflow">if</span> (last_focused != NULL) {
<a name="l00280"></a>00280                                 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;raising above frame %p / child %p\n&quot;</span>, last_focused-&gt;<a class="code" href="a00007.html#ae6bb442465a95e5794ed34936fa67bac" title="Our window: The frame around the client.">frame</a>, last_focused-&gt;<a class="code" href="a00007.html#afba312b946fa74727ce619a33f8f28aa" title="The client’s window.">child</a>);
<a name="l00281"></a>00281                                 uint32_t values[] = { last_focused-&gt;<a class="code" href="a00007.html#ae6bb442465a95e5794ed34936fa67bac" title="Our window: The frame around the client.">frame</a>, XCB_STACK_MODE_ABOVE };
<a name="l00282"></a>00282                                 xcb_configure_window(conn, client-&gt;<a class="code" href="a00007.html#ae6bb442465a95e5794ed34936fa67bac" title="Our window: The frame around the client.">frame</a>, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, values);
<a name="l00283"></a>00283                         }
<a name="l00284"></a>00284                 }
<a name="l00285"></a>00285 
<a name="l00286"></a>00286                 <span class="comment">/* If it is the same one as old_client, we save us the unnecessary redecorate */</span>
<a name="l00287"></a>00287                 <span class="keywordflow">if</span> ((last_focused != NULL) &amp;&amp; (last_focused != old_client))
<a name="l00288"></a>00288                         <a class="code" href="a00069.html#ac78b8a4b371d2c4c2800c765f46e5df3" title="Redecorates the given client correctly by checking if it’s in a stacking container...">redecorate_window</a>(conn, last_focused);
<a name="l00289"></a>00289         }
<a name="l00290"></a>00290 
<a name="l00291"></a>00291         <span class="comment">/* If the last client was a floating client, we need to go to the next</span>
<a name="l00292"></a>00292 <span class="comment">         * tiling client in stack and re-decorate it. */</span>
<a name="l00293"></a>00293         <span class="keywordflow">if</span> (old_client != NULL &amp;&amp; <a class="code" href="a00060.html#a56065826f75013837bc8e125c8dc66c7" title="Returns true if the client is floating.">client_is_floating</a>(old_client)) {
<a name="l00294"></a>00294                 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;Coming from floating client, searching next tiling...\n&quot;</span>);
<a name="l00295"></a>00295                 <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *current;
<a name="l00296"></a>00296                 <a class="code" href="a00047.html#a05db87878125c27e3060dd641aa3b0f4">SLIST_FOREACH</a>(current, &amp;(client-&gt;<a class="code" href="a00007.html#ab9573ba898dbd1932f5200be5eb2a990" title="Because dock clients don’t have a container, we have this workspace-backpointer...">workspace</a>-&gt;focus_stack), focus_clients) {
<a name="l00297"></a>00297                         <span class="keywordflow">if</span> (<a class="code" href="a00060.html#a56065826f75013837bc8e125c8dc66c7" title="Returns true if the client is floating.">client_is_floating</a>(current))
<a name="l00298"></a>00298                                 <span class="keywordflow">continue</span>;
<a name="l00299"></a>00299 
<a name="l00300"></a>00300                         <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;Found window: %p / child %p\n&quot;</span>, current-&gt;<a class="code" href="a00007.html#ae6bb442465a95e5794ed34936fa67bac" title="Our window: The frame around the client.">frame</a>, current-&gt;<a class="code" href="a00007.html#afba312b946fa74727ce619a33f8f28aa" title="The client’s window.">child</a>);
<a name="l00301"></a>00301                         <a class="code" href="a00069.html#ac78b8a4b371d2c4c2800c765f46e5df3" title="Redecorates the given client correctly by checking if it’s in a stacking container...">redecorate_window</a>(conn, current);
<a name="l00302"></a>00302                         <span class="keywordflow">break</span>;
<a name="l00303"></a>00303                 }
<a name="l00304"></a>00304         }
<a name="l00305"></a>00305 
<a name="l00306"></a>00306         <a class="code" href="a00047.html#a9c7950d61593ab9198524fca81b17ab0">SLIST_REMOVE</a>(&amp;(client-&gt;<a class="code" href="a00007.html#ab9573ba898dbd1932f5200be5eb2a990" title="Because dock clients don’t have a container, we have this workspace-backpointer...">workspace</a>-&gt;focus_stack), client, <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a>, focus_clients);
<a name="l00307"></a>00307         <a class="code" href="a00047.html#a48df7439e09a419afabdd1f2f8551e73">SLIST_INSERT_HEAD</a>(&amp;(client-&gt;<a class="code" href="a00007.html#ab9573ba898dbd1932f5200be5eb2a990" title="Because dock clients don’t have a container, we have this workspace-backpointer...">workspace</a>-&gt;focus_stack), client, focus_clients);
<a name="l00308"></a>00308 
<a name="l00309"></a>00309         <span class="comment">/* Clear the urgency flag if set (necessary when i3 sets the flag, for</span>
<a name="l00310"></a>00310 <span class="comment">         * example when automatically putting windows on the workspace of their</span>
<a name="l00311"></a>00311 <span class="comment">         * leader) */</span>
<a name="l00312"></a>00312         client-&gt;<a class="code" href="a00007.html#ad169bd46b1c1edf6f7cddf2c0c5306c7" title="True if the client set the urgency flag in its WM_HINTS property.">urgent</a> = <span class="keyword">false</span>;
<a name="l00313"></a>00313         <a class="code" href="a00078.html#a2c43568cc3492bd24992d93f4552bbe9" title="Goes through all clients on the given workspace and updates the workspace’s urgent...">workspace_update_urgent_flag</a>(client-&gt;<a class="code" href="a00007.html#ab9573ba898dbd1932f5200be5eb2a990" title="Because dock clients don’t have a container, we have this workspace-backpointer...">workspace</a>);
<a name="l00314"></a>00314 
<a name="l00315"></a>00315         <span class="comment">/* If we’re in stacking mode, this renders the container to update changes in the title</span>
<a name="l00316"></a>00316 <span class="comment">           bars and to raise the focused client */</span>
<a name="l00317"></a>00317         <span class="keywordflow">if</span> ((old_client != NULL) &amp;&amp; (old_client != client) &amp;&amp; !old_client-&gt;<a class="code" href="a00007.html#a994b0c5a9eb35e42f04a0b845a3166ef" title="If a client is set as a dock, it is placed at the very bottom of the screen and its...">dock</a>)
<a name="l00318"></a>00318                 <a class="code" href="a00069.html#ac78b8a4b371d2c4c2800c765f46e5df3" title="Redecorates the given client correctly by checking if it’s in a stacking container...">redecorate_window</a>(conn, old_client);
<a name="l00319"></a>00319 
<a name="l00320"></a>00320         <span class="comment">/* redecorate_window flushes, so we don’t need to */</span>
<a name="l00321"></a>00321         <a class="code" href="a00069.html#ac78b8a4b371d2c4c2800c765f46e5df3" title="Redecorates the given client correctly by checking if it’s in a stacking container...">redecorate_window</a>(conn, client);
<a name="l00322"></a>00322 }
<a name="l00323"></a>00323 
<a name="l00324"></a>00324 <span class="comment">/*</span>
<a name="l00325"></a>00325 <span class="comment"> * Called when the user switches to another mode or when the container is</span>
<a name="l00326"></a>00326 <span class="comment"> * destroyed and thus needs to be cleaned up.</span>
<a name="l00327"></a>00327 <span class="comment"> *</span>
<a name="l00328"></a>00328 <span class="comment"> */</span>
<a name="l00329"></a><a class="code" href="a00052.html#a796c789f58b40c431d9c35860585367e">00329</a> <span class="keywordtype">void</span> <a class="code" href="a00077.html#a796c789f58b40c431d9c35860585367e" title="Called when the user switches to another mode or when the container is destroyed...">leave_stack_mode</a>(xcb_connection_t *conn, <a class="code" href="a00013.html" title="A container is either in default, stacking or tabbed mode.">Container</a> *container) {
<a name="l00330"></a>00330         <span class="comment">/* When going out of stacking mode, we need to close the window */</span>
<a name="l00331"></a>00331         <span class="keyword">struct </span><a class="code" href="a00023.html" title="Contains data for the windows needed to draw the titlebars on in stacking mode.">Stack_Window</a> *stack_win = &amp;(container-&gt;<a class="code" href="a00013.html#ad3c94b066b8ddd9a56f33e8bd9f200b2">stack_win</a>);
<a name="l00332"></a>00332 
<a name="l00333"></a>00333         <a class="code" href="a00047.html#a9c7950d61593ab9198524fca81b17ab0">SLIST_REMOVE</a>(&amp;<a class="code" href="a00071.html#ac38e5cddf6395c52d3755d7b368e4a2b">stack_wins</a>, stack_win, <a class="code" href="a00023.html" title="Contains data for the windows needed to draw the titlebars on in stacking mode.">Stack_Window</a>, stack_windows);
<a name="l00334"></a>00334 
<a name="l00335"></a>00335         xcb_free_gc(conn, stack_win-&gt;<a class="code" href="a00023.html#aaa74ae431448b315a0a89cc8cb4e83fc">pixmap</a>.<a class="code" href="a00004.html#a1930bbf9d5570906ace6d8aaeea0cbf1">gc</a>);
<a name="l00336"></a>00336         xcb_free_pixmap(conn, stack_win-&gt;<a class="code" href="a00023.html#aaa74ae431448b315a0a89cc8cb4e83fc">pixmap</a>.<a class="code" href="a00004.html#a75c370b918b9f963d6430ba07e7c56bf">id</a>);
<a name="l00337"></a>00337         xcb_destroy_window(conn, stack_win-&gt;<a class="code" href="a00023.html#aa10861a9e5d4859d70275b462acfcd24">window</a>);
<a name="l00338"></a>00338 
<a name="l00339"></a>00339         stack_win-&gt;<a class="code" href="a00023.html#ac42bcee20d4f77f4ecbdec1dbb616a4f">rect</a>.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a> = -1;
<a name="l00340"></a>00340         stack_win-&gt;<a class="code" href="a00023.html#ac42bcee20d4f77f4ecbdec1dbb616a4f">rect</a>.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a> = -1;
<a name="l00341"></a>00341 }
<a name="l00342"></a>00342 
<a name="l00343"></a>00343 <span class="comment">/*</span>
<a name="l00344"></a>00344 <span class="comment"> * Switches the layout of the given container taking care of the necessary house-keeping</span>
<a name="l00345"></a>00345 <span class="comment"> *</span>
<a name="l00346"></a>00346 <span class="comment"> */</span>
<a name="l00347"></a><a class="code" href="a00052.html#a5b3f86291e1bab74d7edc044a9d87a52">00347</a> <span class="keywordtype">void</span> <a class="code" href="a00077.html#a5b3f86291e1bab74d7edc044a9d87a52" title="Switches the layout of the given container taking care of the necessary house-keeping...">switch_layout_mode</a>(xcb_connection_t *conn, <a class="code" href="a00013.html" title="A container is either in default, stacking or tabbed mode.">Container</a> *<a class="code" href="a00023.html#ad5f9402c2db288b0762e3a6467257dc8" title="Backpointer to the container this stack window is in.">container</a>, <span class="keywordtype">int</span> mode) {
<a name="l00348"></a>00348         <span class="keywordflow">if</span> (mode == MODE_STACK || mode == MODE_TABBED) {
<a name="l00349"></a>00349                 <span class="comment">/* When we’re already in stacking mode, nothing has to be done */</span>
<a name="l00350"></a>00350                 <span class="keywordflow">if</span> ((mode == MODE_STACK &amp;&amp; container-&gt;<a class="code" href="a00013.html#ac094306ab77e360742aba04d7cbd0fe6">mode</a> == MODE_STACK) ||
<a name="l00351"></a>00351                     (mode == MODE_TABBED &amp;&amp; container-&gt;<a class="code" href="a00013.html#ac094306ab77e360742aba04d7cbd0fe6">mode</a> == MODE_TABBED))
<a name="l00352"></a>00352                         <span class="keywordflow">return</span>;
<a name="l00353"></a>00353 
<a name="l00354"></a>00354                 <span class="keywordflow">if</span> (container-&gt;<a class="code" href="a00013.html#ac094306ab77e360742aba04d7cbd0fe6">mode</a> == MODE_STACK || container-&gt;<a class="code" href="a00013.html#ac094306ab77e360742aba04d7cbd0fe6">mode</a> == MODE_TABBED)
<a name="l00355"></a>00355                         <span class="keywordflow">goto</span> after_stackwin;
<a name="l00356"></a>00356 
<a name="l00357"></a>00357                 <span class="comment">/* When entering stacking mode, we need to open a window on</span>
<a name="l00358"></a>00358 <span class="comment">                 * which we can draw the title bars of the clients, it has</span>
<a name="l00359"></a>00359 <span class="comment">                 * height 1 because we don’t bother here with calculating the</span>
<a name="l00360"></a>00360 <span class="comment">                 * correct height - it will be adjusted when rendering anyways.</span>
<a name="l00361"></a>00361 <span class="comment">                 * Also, we need to use max(width, 1) because windows cannot</span>
<a name="l00362"></a>00362 <span class="comment">                 * be created with either width == 0 or height == 0. */</span>
<a name="l00363"></a>00363                 <a class="code" href="a00020.html" title="Stores a rectangle, for example the size of a window, the child window etc.">Rect</a> <a class="code" href="a00023.html#ac42bcee20d4f77f4ecbdec1dbb616a4f">rect</a> = {container-&gt;<a class="code" href="a00013.html#a4829135d344139fb1c9e25ae5cdf5747">x</a>, container-&gt;<a class="code" href="a00013.html#a31cfaffc96b7c938a239bd40c1488230">y</a>, <a class="code" href="a00077.html#af082905f7eac6d03e92015146bbc1925">max</a>(container-&gt;<a class="code" href="a00013.html#af9b566fc3a8a208897503254747ae720">width</a>, 1), 1};
<a name="l00364"></a>00364 
<a name="l00365"></a>00365                 uint32_t mask = 0;
<a name="l00366"></a>00366                 uint32_t values[2];
<a name="l00367"></a>00367 
<a name="l00368"></a>00368                 <span class="comment">/* Don’t generate events for our new window, it should *not* be managed */</span>
<a name="l00369"></a>00369                 mask |= XCB_CW_OVERRIDE_REDIRECT;
<a name="l00370"></a>00370                 values[0] = 1;
<a name="l00371"></a>00371 
<a name="l00372"></a>00372                 <span class="comment">/* We want to know when… */</span>
<a name="l00373"></a>00373                 mask |= XCB_CW_EVENT_MASK;
<a name="l00374"></a>00374                 values[1] =     XCB_EVENT_MASK_ENTER_WINDOW |   <span class="comment">/* …mouse is moved into our window */</span>
<a name="l00375"></a>00375                                 XCB_EVENT_MASK_BUTTON_PRESS |   <span class="comment">/* …mouse is pressed */</span>
<a name="l00376"></a>00376                                 XCB_EVENT_MASK_EXPOSURE;        <span class="comment">/* …our window needs to be redrawn */</span>
<a name="l00377"></a>00377 
<a name="l00378"></a>00378                 <span class="keyword">struct </span><a class="code" href="a00023.html" title="Contains data for the windows needed to draw the titlebars on in stacking mode.">Stack_Window</a> *stack_win = &amp;(container-&gt;<a class="code" href="a00013.html#ad3c94b066b8ddd9a56f33e8bd9f200b2">stack_win</a>);
<a name="l00379"></a>00379                 stack_win-&gt;<a class="code" href="a00023.html#aa10861a9e5d4859d70275b462acfcd24">window</a> = <a class="code" href="a00079.html#a1c6bb71a9f8e0501e2228dd3dca3bd6a" title="Convenience wrapper around xcb_create_window which takes care of depth, generating...">create_window</a>(conn, rect, XCB_WINDOW_CLASS_INPUT_OUTPUT, <a class="code" href="a00054.html#ada5e89d9bddd5e5feff900639db2e208" title="This is the equivalent of XC_left_ptr.">XCB_CURSOR_LEFT_PTR</a>, <span class="keyword">false</span>, mask, values);
<a name="l00380"></a>00380 
<a name="l00381"></a>00381                 stack_win-&gt;<a class="code" href="a00023.html#ac42bcee20d4f77f4ecbdec1dbb616a4f">rect</a>.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a> = 0;
<a name="l00382"></a>00382 
<a name="l00383"></a>00383                 <span class="comment">/* Initialize the entry for our cached pixmap. It will be</span>
<a name="l00384"></a>00384 <span class="comment">                 * created as soon as it’s needed (see cached_pixmap_prepare). */</span>
<a name="l00385"></a>00385                 memset(&amp;(stack_win-&gt;<a class="code" href="a00023.html#aaa74ae431448b315a0a89cc8cb4e83fc">pixmap</a>), 0, <span class="keyword">sizeof</span>(<span class="keyword">struct</span> <a class="code" href="a00004.html">Cached_Pixmap</a>));
<a name="l00386"></a>00386                 stack_win-&gt;<a class="code" href="a00023.html#aaa74ae431448b315a0a89cc8cb4e83fc">pixmap</a>.<a class="code" href="a00004.html#a34c59c8ce74f3d808ec0a045b138be39">referred_rect</a> = &amp;stack_win-&gt;<a class="code" href="a00023.html#ac42bcee20d4f77f4ecbdec1dbb616a4f">rect</a>;
<a name="l00387"></a>00387                 stack_win-&gt;<a class="code" href="a00023.html#aaa74ae431448b315a0a89cc8cb4e83fc">pixmap</a>.<a class="code" href="a00004.html#ad05fd81000b6ee526f8a737b043edb8a">referred_drawable</a> = stack_win-&gt;<a class="code" href="a00023.html#aa10861a9e5d4859d70275b462acfcd24">window</a>;
<a name="l00388"></a>00388 
<a name="l00389"></a>00389                 stack_win-&gt;<a class="code" href="a00023.html#ad5f9402c2db288b0762e3a6467257dc8" title="Backpointer to the container this stack window is in.">container</a> = container;
<a name="l00390"></a>00390 
<a name="l00391"></a>00391                 <a class="code" href="a00047.html#a48df7439e09a419afabdd1f2f8551e73">SLIST_INSERT_HEAD</a>(&amp;<a class="code" href="a00071.html#ac38e5cddf6395c52d3755d7b368e4a2b">stack_wins</a>, stack_win, stack_windows);
<a name="l00392"></a>00392         } <span class="keywordflow">else</span> {
<a name="l00393"></a>00393                 <span class="keywordflow">if</span> (container-&gt;<a class="code" href="a00013.html#ac094306ab77e360742aba04d7cbd0fe6">mode</a> == MODE_STACK || container-&gt;<a class="code" href="a00013.html#ac094306ab77e360742aba04d7cbd0fe6">mode</a> == MODE_TABBED)
<a name="l00394"></a>00394                         <a class="code" href="a00077.html#a796c789f58b40c431d9c35860585367e" title="Called when the user switches to another mode or when the container is destroyed...">leave_stack_mode</a>(conn, container);
<a name="l00395"></a>00395         }
<a name="l00396"></a>00396 after_stackwin:
<a name="l00397"></a>00397         container-&gt;<a class="code" href="a00013.html#ac094306ab77e360742aba04d7cbd0fe6">mode</a> = mode;
<a name="l00398"></a>00398 
<a name="l00399"></a>00399         <span class="comment">/* Force reconfiguration of each client */</span>
<a name="l00400"></a>00400         <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *client;
<a name="l00401"></a>00401 
<a name="l00402"></a>00402         <a class="code" href="a00047.html#ae97f4eb5724477c63699fafea4614b46">CIRCLEQ_FOREACH</a>(client, &amp;(container-&gt;clients), clients)
<a name="l00403"></a>00403                 client-&gt;<a class="code" href="a00007.html#a873c62703ab51afe96b38df2b30ffa66">force_reconfigure</a> = <span class="keyword">true</span>;
<a name="l00404"></a>00404 
<a name="l00405"></a>00405         <a class="code" href="a00069.html#a47ffef7db851301198762179187ac997" title="Renders the whole layout, that is: Go through each screen, each workspace, each container...">render_layout</a>(conn);
<a name="l00406"></a>00406 
<a name="l00407"></a>00407         <span class="keywordflow">if</span> (container-&gt;<a class="code" href="a00013.html#a82d910506b0d788a92ebeeb1d82da75b">currently_focused</a> != NULL) {
<a name="l00408"></a>00408                 <span class="comment">/* We need to make sure that this client is above *each* of the</span>
<a name="l00409"></a>00409 <span class="comment">                 * other clients in this container */</span>
<a name="l00410"></a>00410                 <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *last_focused = <a class="code" href="a00077.html#ad5a21e1f5f7065c1997717c13559907a" title="Returns the client which comes next in focus stack (= was selected before) for the...">get_last_focused_client</a>(conn, container, container-&gt;<a class="code" href="a00013.html#a82d910506b0d788a92ebeeb1d82da75b">currently_focused</a>);
<a name="l00411"></a>00411 
<a name="l00412"></a>00412                 <a class="code" href="a00047.html#ae97f4eb5724477c63699fafea4614b46">CIRCLEQ_FOREACH</a>(client, &amp;(container-&gt;clients), clients) {
<a name="l00413"></a>00413                         <span class="keywordflow">if</span> (client == container-&gt;<a class="code" href="a00013.html#a82d910506b0d788a92ebeeb1d82da75b">currently_focused</a> || client == last_focused)
<a name="l00414"></a>00414                                 <span class="keywordflow">continue</span>;
<a name="l00415"></a>00415 
<a name="l00416"></a>00416                         <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;setting %08x below %08x / %08x\n&quot;</span>, client-&gt;<a class="code" href="a00007.html#ae6bb442465a95e5794ed34936fa67bac" title="Our window: The frame around the client.">frame</a>, container-&gt;<a class="code" href="a00013.html#a82d910506b0d788a92ebeeb1d82da75b">currently_focused</a>-&gt;<a class="code" href="a00007.html#ae6bb442465a95e5794ed34936fa67bac" title="Our window: The frame around the client.">frame</a>);
<a name="l00417"></a>00417                         uint32_t values[] = { container-&gt;<a class="code" href="a00013.html#a82d910506b0d788a92ebeeb1d82da75b">currently_focused</a>-&gt;<a class="code" href="a00007.html#ae6bb442465a95e5794ed34936fa67bac" title="Our window: The frame around the client.">frame</a>, XCB_STACK_MODE_BELOW };
<a name="l00418"></a>00418                         xcb_configure_window(conn, client-&gt;<a class="code" href="a00007.html#ae6bb442465a95e5794ed34936fa67bac" title="Our window: The frame around the client.">frame</a>,
<a name="l00419"></a>00419                                              XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, values);
<a name="l00420"></a>00420                 }
<a name="l00421"></a>00421 
<a name="l00422"></a>00422                 <span class="keywordflow">if</span> (last_focused != NULL) {
<a name="l00423"></a>00423                         <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;Putting last_focused directly underneath the currently focused\n&quot;</span>);
<a name="l00424"></a>00424                         uint32_t values[] = { container-&gt;<a class="code" href="a00013.html#a82d910506b0d788a92ebeeb1d82da75b">currently_focused</a>-&gt;<a class="code" href="a00007.html#ae6bb442465a95e5794ed34936fa67bac" title="Our window: The frame around the client.">frame</a>, XCB_STACK_MODE_BELOW };
<a name="l00425"></a>00425                         xcb_configure_window(conn, last_focused-&gt;<a class="code" href="a00007.html#ae6bb442465a95e5794ed34936fa67bac" title="Our window: The frame around the client.">frame</a>,
<a name="l00426"></a>00426                                              XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, values);
<a name="l00427"></a>00427                 }
<a name="l00428"></a>00428 
<a name="l00429"></a>00429 
<a name="l00430"></a>00430                 <a class="code" href="a00077.html#a323dcf30475bb3bf165100e74d225b48" title="Sets the given client as focused by updating the data structures correctly, updating...">set_focus</a>(conn, container-&gt;<a class="code" href="a00013.html#a82d910506b0d788a92ebeeb1d82da75b">currently_focused</a>, <span class="keyword">true</span>);
<a name="l00431"></a>00431         }
<a name="l00432"></a>00432 }
<a name="l00433"></a>00433 
<a name="l00434"></a>00434 <span class="comment">/*</span>
<a name="l00435"></a>00435 <span class="comment"> * Gets the first matching client for the given window class/window title.</span>
<a name="l00436"></a>00436 <span class="comment"> * If the paramater specific is set to a specific client, only this one</span>
<a name="l00437"></a>00437 <span class="comment"> * will be checked.</span>
<a name="l00438"></a>00438 <span class="comment"> *</span>
<a name="l00439"></a>00439 <span class="comment"> */</span>
<a name="l00440"></a><a class="code" href="a00052.html#ad77b9ae748e9583f072306af098dafed">00440</a> <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *<a class="code" href="a00077.html#ad77b9ae748e9583f072306af098dafed" title="Gets the first matching client for the given window class/window title.">get_matching_client</a>(xcb_connection_t *conn, <span class="keyword">const</span> <span class="keywordtype">char</span> *window_classtitle,
<a name="l00441"></a>00441                             <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *specific) {
<a name="l00442"></a>00442         <span class="keywordtype">char</span> *to_class, *to_title, *to_title_ucs = NULL;
<a name="l00443"></a>00443         <span class="keywordtype">int</span> to_title_ucs_len = 0;
<a name="l00444"></a>00444         <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *matching = NULL;
<a name="l00445"></a>00445 
<a name="l00446"></a>00446         to_class = <a class="code" href="a00077.html#a11822d1f4b182be3fa03d2a5af536e1a" title="Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there...">sstrdup</a>(window_classtitle);
<a name="l00447"></a>00447 
<a name="l00448"></a>00448         <span class="comment">/* If a title was specified, split both strings at the slash */</span>
<a name="l00449"></a>00449         <span class="keywordflow">if</span> ((to_title = strstr(to_class, <span class="stringliteral">&quot;/&quot;</span>)) != NULL) {
<a name="l00450"></a>00450                 *(to_title++) = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l00451"></a>00451                 <span class="comment">/* Convert to UCS-2 */</span>
<a name="l00452"></a>00452                 to_title_ucs = <a class="code" href="a00077.html#a1d926a6371d3d87f2dd85c1a27d83f4b" title="Converts the given string to UCS-2 big endian for use with xcb_image_text_16().">convert_utf8_to_ucs2</a>(to_title, &amp;to_title_ucs_len);
<a name="l00453"></a>00453         }
<a name="l00454"></a>00454 
<a name="l00455"></a>00455         <span class="comment">/* If we were given a specific client we only check if that one matches */</span>
<a name="l00456"></a>00456         <span class="keywordflow">if</span> (specific != NULL) {
<a name="l00457"></a>00457                 <span class="keywordflow">if</span> (<a class="code" href="a00060.html#ace28c5dcca4e3a62a20429038d3bed50" title="Checks if the given window class and title match the given client Window title is...">client_matches_class_name</a>(specific, to_class, to_title, to_title_ucs, to_title_ucs_len))
<a name="l00458"></a>00458                         matching = specific;
<a name="l00459"></a>00459                 <span class="keywordflow">goto</span> done;
<a name="l00460"></a>00460         }
<a name="l00461"></a>00461 
<a name="l00462"></a>00462         <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;Getting clients for class \&quot;%s\&quot; / title \&quot;%s\&quot;\n&quot;</span>, to_class, to_title);
<a name="l00463"></a>00463         <a class="code" href="a00025.html" title="The concept of Workspaces is known from various other window managers.">Workspace</a> *ws;
<a name="l00464"></a>00464         <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="l00465"></a>00465                 <span class="keywordflow">if</span> (ws-&gt;<a class="code" href="a00025.html#aeee203e013dae84555d28f8247a7e375" title="Backpointer to the output this workspace is on.">output</a> == NULL)
<a name="l00466"></a>00466                         <span class="keywordflow">continue</span>;
<a name="l00467"></a>00467 
<a name="l00468"></a>00468                 <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *client;
<a name="l00469"></a>00469                 <a class="code" href="a00047.html#a05db87878125c27e3060dd641aa3b0f4">SLIST_FOREACH</a>(client, &amp;(ws-&gt;focus_stack), focus_clients) {
<a name="l00470"></a>00470                         <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;Checking client with class=%s / %s, name=%s\n&quot;</span>, client-&gt;<a class="code" href="a00007.html#ac39c70e8b92f752b81f2c5cca3522399" title="Holds the WM_CLASS (which consists of two strings, the instance and the class), useful...">window_class_instance</a>,
<a name="l00471"></a>00471                              client-&gt;<a class="code" href="a00007.html#a1c231d29bfbf4213354bb5ac43bacfa4">window_class_class</a>, client-&gt;<a class="code" href="a00007.html#a14c9eb7f57edfd939ed2fada25e83916" title="Name (= window title).">name</a>);
<a name="l00472"></a>00472                         <span class="keywordflow">if</span> (!<a class="code" href="a00060.html#ace28c5dcca4e3a62a20429038d3bed50" title="Checks if the given window class and title match the given client Window title is...">client_matches_class_name</a>(client, to_class, to_title, to_title_ucs, to_title_ucs_len))
<a name="l00473"></a>00473                                 <span class="keywordflow">continue</span>;
<a name="l00474"></a>00474 
<a name="l00475"></a>00475                         matching = client;
<a name="l00476"></a>00476                         <span class="keywordflow">goto</span> done;
<a name="l00477"></a>00477                 }
<a name="l00478"></a>00478         }
<a name="l00479"></a>00479 
<a name="l00480"></a>00480 done:
<a name="l00481"></a>00481         free(to_class);
<a name="l00482"></a>00482         <a class="code" href="a00052.html#ae88e84de75be0b138a19509d288b4cf4">FREE</a>(to_title_ucs);
<a name="l00483"></a>00483         <span class="keywordflow">return</span> matching;
<a name="l00484"></a>00484 }
<a name="l00485"></a>00485 
<a name="l00486"></a>00486 <span class="comment">/*</span>
<a name="l00487"></a>00487 <span class="comment"> * Goes through the list of arguments (for exec()) and checks if the given argument</span>
<a name="l00488"></a>00488 <span class="comment"> * is present. If not, it copies the arguments (because we cannot realloc it) and</span>
<a name="l00489"></a>00489 <span class="comment"> * appends the given argument.</span>
<a name="l00490"></a>00490 <span class="comment"> *</span>
<a name="l00491"></a>00491 <span class="comment"> */</span>
<a name="l00492"></a><a class="code" href="a00077.html#ab2bd44ab8b1c1b843c6c7ba6f76227e2">00492</a> <span class="keyword">static</span> <span class="keywordtype">char</span> **<a class="code" href="a00077.html#ab2bd44ab8b1c1b843c6c7ba6f76227e2">append_argument</a>(<span class="keywordtype">char</span> **original, <span class="keywordtype">char</span> *argument) {
<a name="l00493"></a>00493         <span class="keywordtype">int</span> num_args;
<a name="l00494"></a>00494         <span class="keywordflow">for</span> (num_args = 0; original[num_args] != NULL; num_args++) {
<a name="l00495"></a>00495                 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;original argument: \&quot;%s\&quot;\n&quot;</span>, original[num_args]);
<a name="l00496"></a>00496                 <span class="comment">/* If the argument is already present we return the original pointer */</span>
<a name="l00497"></a>00497                 <span class="keywordflow">if</span> (strcmp(original[num_args], argument) == 0)
<a name="l00498"></a>00498                         <span class="keywordflow">return</span> original;
<a name="l00499"></a>00499         }
<a name="l00500"></a>00500         <span class="comment">/* Copy the original array */</span>
<a name="l00501"></a>00501         <span class="keywordtype">char</span> **result = <a class="code" href="a00077.html#a46c23cb2833f4b674f5cfc977f16b990" title="Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there...">smalloc</a>((num_args+2) * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
<a name="l00502"></a>00502         memcpy(result, original, num_args * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*));
<a name="l00503"></a>00503         result[num_args] = argument;
<a name="l00504"></a>00504         result[num_args+1] = NULL;
<a name="l00505"></a>00505 
<a name="l00506"></a>00506         <span class="keywordflow">return</span> result;
<a name="l00507"></a>00507 }
<a name="l00508"></a>00508 
<a name="l00509"></a>00509 <span class="comment">/*</span>
<a name="l00510"></a>00510 <span class="comment"> * Restart i3 in-place</span>
<a name="l00511"></a>00511 <span class="comment"> * appends -a to argument list to disable autostart</span>
<a name="l00512"></a>00512 <span class="comment"> *</span>
<a name="l00513"></a>00513 <span class="comment"> */</span>
<a name="l00514"></a><a class="code" href="a00052.html#aa6932bace7059f6a57068cdf87de1e1f">00514</a> <span class="keywordtype">void</span> <a class="code" href="a00077.html#aa6932bace7059f6a57068cdf87de1e1f">i3_restart</a>() {
<a name="l00515"></a>00515         <a class="code" href="a00072.html#a7a5eac8069bf76ea873503dd80100544" title="Restores the geometry of each window by reparenting it to the root window at the...">restore_geometry</a>(<a class="code" href="a00071.html#ada13c42121d64521629e06e7a5e1db16">global_conn</a>);
<a name="l00516"></a>00516 
<a name="l00517"></a>00517         <a class="code" href="a00068.html#ae12d3a1c83452d7fb9b9ae9ce23bb424" title="Calls shutdown() on each socket and closes it.">ipc_shutdown</a>();
<a name="l00518"></a>00518 
<a name="l00519"></a>00519         <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">&quot;restarting \&quot;%s\&quot;...\n&quot;</span>, <a class="code" href="a00071.html#adff3468c46bf36c35842552ad6cd220d">start_argv</a>[0]);
<a name="l00520"></a>00520         <span class="comment">/* make sure -a is in the argument list or append it */</span>
<a name="l00521"></a>00521         <a class="code" href="a00071.html#adff3468c46bf36c35842552ad6cd220d">start_argv</a> = <a class="code" href="a00077.html#ab2bd44ab8b1c1b843c6c7ba6f76227e2">append_argument</a>(<a class="code" href="a00071.html#adff3468c46bf36c35842552ad6cd220d">start_argv</a>, <span class="stringliteral">&quot;-a&quot;</span>);
<a name="l00522"></a>00522 
<a name="l00523"></a>00523         execvp(<a class="code" href="a00071.html#adff3468c46bf36c35842552ad6cd220d">start_argv</a>[0], <a class="code" href="a00071.html#adff3468c46bf36c35842552ad6cd220d">start_argv</a>);
<a name="l00524"></a>00524         <span class="comment">/* not reached */</span>
<a name="l00525"></a>00525 }
<a name="l00526"></a>00526 
<a name="l00527"></a>00527 <span class="preprocessor">#if defined(__OpenBSD__)</span>
<a name="l00528"></a>00528 <span class="preprocessor"></span>
<a name="l00529"></a>00529 <span class="comment">/*</span>
<a name="l00530"></a>00530 <span class="comment"> * Taken from FreeBSD</span>
<a name="l00531"></a>00531 <span class="comment"> * Find the first occurrence of the byte string s in byte string l.</span>
<a name="l00532"></a>00532 <span class="comment"> *</span>
<a name="l00533"></a>00533 <span class="comment"> */</span>
<a name="l00534"></a>00534 <span class="keywordtype">void</span> *memmem(<span class="keyword">const</span> <span class="keywordtype">void</span> *l, <span class="keywordtype">size_t</span> l_len, <span class="keyword">const</span> <span class="keywordtype">void</span> *s, <span class="keywordtype">size_t</span> s_len) {
<a name="l00535"></a>00535         <span class="keyword">register</span> <span class="keywordtype">char</span> *cur, *last;
<a name="l00536"></a>00536         <span class="keyword">const</span> <span class="keywordtype">char</span> *cl = (<span class="keyword">const</span> <span class="keywordtype">char</span> *)l;
<a name="l00537"></a>00537         <span class="keyword">const</span> <span class="keywordtype">char</span> *cs = (<span class="keyword">const</span> <span class="keywordtype">char</span> *)s;
<a name="l00538"></a>00538 
<a name="l00539"></a>00539         <span class="comment">/* we need something to compare */</span>
<a name="l00540"></a>00540         <span class="keywordflow">if</span> (l_len == 0 || s_len == 0)
<a name="l00541"></a>00541                 <span class="keywordflow">return</span> NULL;
<a name="l00542"></a>00542 
<a name="l00543"></a>00543         <span class="comment">/* &quot;s&quot; must be smaller or equal to &quot;l&quot; */</span>
<a name="l00544"></a>00544         <span class="keywordflow">if</span> (l_len &lt; s_len)
<a name="l00545"></a>00545                 <span class="keywordflow">return</span> NULL;
<a name="l00546"></a>00546 
<a name="l00547"></a>00547         <span class="comment">/* special case where s_len == 1 */</span>
<a name="l00548"></a>00548         <span class="keywordflow">if</span> (s_len == 1)
<a name="l00549"></a>00549                 <span class="keywordflow">return</span> memchr(l, (<span class="keywordtype">int</span>)*cs, l_len);
<a name="l00550"></a>00550 
<a name="l00551"></a>00551         <span class="comment">/* the last position where its possible to find &quot;s&quot; in &quot;l&quot; */</span>
<a name="l00552"></a>00552         last = (<span class="keywordtype">char</span> *)cl + l_len - s_len;
<a name="l00553"></a>00553 
<a name="l00554"></a>00554         <span class="keywordflow">for</span> (cur = (<span class="keywordtype">char</span> *)cl; cur &lt;= last; cur++)
<a name="l00555"></a>00555                 <span class="keywordflow">if</span> (cur[0] == cs[0] &amp;&amp; memcmp(cur, cs, s_len) == 0)
<a name="l00556"></a>00556                         <span class="keywordflow">return</span> cur;
<a name="l00557"></a>00557 
<a name="l00558"></a>00558         <span class="keywordflow">return</span> NULL;
<a name="l00559"></a>00559 }
<a name="l00560"></a>00560 
<a name="l00561"></a>00561 <span class="preprocessor">#endif</span>
<a name="l00562"></a>00562 <span class="preprocessor"></span>
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated by&nbsp;
<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>