Sophie

Sophie

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

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/sighandler.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/sighandler.c</h1><a href="a00075.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"> * © 2009-2010 Jan-Erik Rediger</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
<a name="l00009"></a>00009 <span class="comment"> * See file LICENSE for license information.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * sighandler.c: contains all functions for signal handling</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> */</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;ev.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;iconv.h&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;signal.h&gt;</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;xcb/xcb.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;xcb/xcb_aux.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;xcb/xcb_event.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;xcb/xcb_keysyms.h&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;X11/keysym.h&gt;</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;<a class="code" href="a00041.html">i3.h</a>&quot;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;<a class="code" href="a00052.html">util.h</a>&quot;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &quot;<a class="code" href="a00054.html">xcb.h</a>&quot;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &quot;<a class="code" href="a00044.html">log.h</a>&quot;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;<a class="code" href="a00034.html">config.h</a>&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;<a class="code" href="a00048.html">randr.h</a>&quot;</span>
<a name="l00035"></a>00035 
<a name="l00036"></a><a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">00036</a> <span class="keyword">static</span> xcb_gcontext_t <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a>;
<a name="l00037"></a><a class="code" href="a00075.html#a81dcec2414a6c7beb665ce0fe5e1eaf6">00037</a> <span class="keyword">static</span> xcb_pixmap_t <a class="code" href="a00075.html#a81dcec2414a6c7beb665ce0fe5e1eaf6">pixmap</a>;
<a name="l00038"></a><a class="code" href="a00075.html#a2b30b9b043c3efde6d659eb0e579998a">00038</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="a00075.html#a2b30b9b043c3efde6d659eb0e579998a">raised_signal</a>;
<a name="l00039"></a>00039 
<a name="l00040"></a><a class="code" href="a00075.html#a64d1c56bede447f9de2cccf6326c5ccb">00040</a> <span class="keyword">static</span> <span class="keywordtype">char</span> *<a class="code" href="a00075.html#a64d1c56bede447f9de2cccf6326c5ccb">crash_text</a>[] = {
<a name="l00041"></a>00041         <span class="stringliteral">&quot;i3 just crashed.&quot;</span>,
<a name="l00042"></a>00042         <span class="stringliteral">&quot;To debug this problem, either attach gdb now&quot;</span>,
<a name="l00043"></a>00043         <span class="stringliteral">&quot;or press &#39;e&#39; to exit and get a core-dump.&quot;</span>,
<a name="l00044"></a>00044         <span class="stringliteral">&quot;If you want to keep your session,&quot;</span>,
<a name="l00045"></a>00045         <span class="stringliteral">&quot;press &#39;r&#39; to restart i3 in-place.&quot;</span>
<a name="l00046"></a>00046 };
<a name="l00047"></a><a class="code" href="a00075.html#adb8e591cad2f13bf07542bb3b488ac3a">00047</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="a00075.html#adb8e591cad2f13bf07542bb3b488ac3a">crash_text_longest</a> = 1;
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="comment">/*</span>
<a name="l00050"></a>00050 <span class="comment"> * Draw the window containing the info text</span>
<a name="l00051"></a>00051 <span class="comment"> *</span>
<a name="l00052"></a>00052 <span class="comment"> */</span>
<a name="l00053"></a><a class="code" href="a00075.html#a31aa6fd12baddf237a3aec1a03e5d9a5">00053</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="a00075.html#a31aa6fd12baddf237a3aec1a03e5d9a5">sig_draw_window</a>(xcb_connection_t *conn, xcb_window_t win, <span class="keywordtype">int</span> width, <span class="keywordtype">int</span> height, <span class="keywordtype">int</span> font_height) {
<a name="l00054"></a>00054         <span class="comment">/* re-draw the background */</span>
<a name="l00055"></a>00055         xcb_rectangle_t border = { 0, 0, width, height},
<a name="l00056"></a>00056                         inner = { 2, 2, width - 4, height - 4};
<a name="l00057"></a>00057         <a class="code" href="a00079.html#ac20ce6b9cf46f63675e363ac5dc2f24e" title="Changes a single value in the graphic context (so one doesn’t have to define an...">xcb_change_gc_single</a>(conn, <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a>, XCB_GC_FOREGROUND, <a class="code" href="a00079.html#a0146fe310e31c9509a7a7846aa547c67" title="Returns the colorpixel to use for the given hex color (think of HTML).">get_colorpixel</a>(conn, <span class="stringliteral">&quot;#FF0000&quot;</span>));
<a name="l00058"></a>00058         xcb_poly_fill_rectangle(conn, <a class="code" href="a00075.html#a81dcec2414a6c7beb665ce0fe5e1eaf6">pixmap</a>, <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a>, 1, &amp;border);
<a name="l00059"></a>00059         <a class="code" href="a00079.html#ac20ce6b9cf46f63675e363ac5dc2f24e" title="Changes a single value in the graphic context (so one doesn’t have to define an...">xcb_change_gc_single</a>(conn, <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a>, XCB_GC_FOREGROUND, <a class="code" href="a00079.html#a0146fe310e31c9509a7a7846aa547c67" title="Returns the colorpixel to use for the given hex color (think of HTML).">get_colorpixel</a>(conn, <span class="stringliteral">&quot;#000000&quot;</span>));
<a name="l00060"></a>00060         xcb_poly_fill_rectangle(conn, <a class="code" href="a00075.html#a81dcec2414a6c7beb665ce0fe5e1eaf6">pixmap</a>, <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a>, 1, &amp;inner);
<a name="l00061"></a>00061 
<a name="l00062"></a>00062         <span class="comment">/* restore font color */</span>
<a name="l00063"></a>00063         <a class="code" href="a00079.html#ac20ce6b9cf46f63675e363ac5dc2f24e" title="Changes a single value in the graphic context (so one doesn’t have to define an...">xcb_change_gc_single</a>(conn, <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a>, XCB_GC_FOREGROUND, <a class="code" href="a00079.html#a0146fe310e31c9509a7a7846aa547c67" title="Returns the colorpixel to use for the given hex color (think of HTML).">get_colorpixel</a>(conn, <span class="stringliteral">&quot;#FFFFFF&quot;</span>));
<a name="l00064"></a>00064 
<a name="l00065"></a>00065         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <span class="keyword">sizeof</span>(<a class="code" href="a00075.html#a64d1c56bede447f9de2cccf6326c5ccb">crash_text</a>) / <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*); i++) {
<a name="l00066"></a>00066                 <span class="keywordtype">int</span> text_len = strlen(<a class="code" href="a00075.html#a64d1c56bede447f9de2cccf6326c5ccb">crash_text</a>[i]);
<a name="l00067"></a>00067                 <span class="keywordtype">char</span> *full_text = <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>(<a class="code" href="a00075.html#a64d1c56bede447f9de2cccf6326c5ccb">crash_text</a>[i], &amp;text_len);
<a name="l00068"></a>00068                 xcb_image_text_16(conn, text_len, <a class="code" href="a00075.html#a81dcec2414a6c7beb665ce0fe5e1eaf6">pixmap</a>, <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a>, 8 <span class="comment">/* X */</span>,
<a name="l00069"></a>00069                                 3 + (i + 1) * font_height <span class="comment">/* Y = baseline of font */</span>,
<a name="l00070"></a>00070                                 (xcb_char2b_t*)full_text);
<a name="l00071"></a>00071                 free(full_text);
<a name="l00072"></a>00072         }
<a name="l00073"></a>00073 
<a name="l00074"></a>00074         <span class="comment">/* Copy the contents of the pixmap to the real window */</span>
<a name="l00075"></a>00075         xcb_copy_area(conn, <a class="code" href="a00075.html#a81dcec2414a6c7beb665ce0fe5e1eaf6">pixmap</a>, win, <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a>, 0, 0, 0, 0, width, height);
<a name="l00076"></a>00076         xcb_flush(conn);
<a name="l00077"></a>00077 
<a name="l00078"></a>00078         <span class="keywordflow">return</span> 1;
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080 
<a name="l00081"></a>00081 <span class="comment">/*</span>
<a name="l00082"></a>00082 <span class="comment"> * Handles keypresses of &#39;e&#39; or &#39;r&#39; to exit or restart i3</span>
<a name="l00083"></a>00083 <span class="comment"> *</span>
<a name="l00084"></a>00084 <span class="comment"> */</span>
<a name="l00085"></a><a class="code" href="a00075.html#afd2deb48146e0d8d84b5bbdbee8b76c7">00085</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="a00075.html#afd2deb48146e0d8d84b5bbdbee8b76c7">sig_handle_key_press</a>(<span class="keywordtype">void</span> *ignored, xcb_connection_t *conn, xcb_key_press_event_t *event) {
<a name="l00086"></a>00086         uint16_t state = <span class="keyword">event</span>-&gt;state;
<a name="l00087"></a>00087 
<a name="l00088"></a>00088         <span class="comment">/* Apparantly, after activating numlock once, the numlock modifier</span>
<a name="l00089"></a>00089 <span class="comment">         * stays turned on (use xev(1) to verify). So, to resolve useful</span>
<a name="l00090"></a>00090 <span class="comment">         * keysyms, we remove the numlock flag from the event state */</span>
<a name="l00091"></a>00091         state &amp;= ~<a class="code" href="a00054.html#ac430ae06cbf6f5ef252c9ebfca47e644">xcb_numlock_mask</a>;
<a name="l00092"></a>00092 
<a name="l00093"></a>00093         xcb_keysym_t sym = xcb_key_press_lookup_keysym(<a class="code" href="a00071.html#a5cc0138ae2cf3bbb63a7cae907620797">keysyms</a>, event, state);
<a name="l00094"></a>00094 
<a name="l00095"></a>00095         <span class="keywordflow">if</span> (sym == <span class="charliteral">&#39;e&#39;</span>) {
<a name="l00096"></a>00096                 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;User issued exit-command, raising error again.\n&quot;</span>);
<a name="l00097"></a>00097                 <span class="keyword">raise</span>(<a class="code" href="a00075.html#a2b30b9b043c3efde6d659eb0e579998a">raised_signal</a>);
<a name="l00098"></a>00098                 exit(1);
<a name="l00099"></a>00099         }
<a name="l00100"></a>00100 
<a name="l00101"></a>00101         <span class="keywordflow">if</span> (sym == <span class="charliteral">&#39;r&#39;</span>)
<a name="l00102"></a>00102                 <a class="code" href="a00077.html#aa6932bace7059f6a57068cdf87de1e1f">i3_restart</a>();
<a name="l00103"></a>00103 
<a name="l00104"></a>00104         <span class="keywordflow">return</span> 1;
<a name="l00105"></a>00105 }
<a name="l00106"></a>00106 
<a name="l00107"></a>00107 <span class="comment">/*</span>
<a name="l00108"></a>00108 <span class="comment"> * Opens the window we use for input/output and maps it</span>
<a name="l00109"></a>00109 <span class="comment"> *</span>
<a name="l00110"></a>00110 <span class="comment"> */</span>
<a name="l00111"></a><a class="code" href="a00075.html#a12a31f7912e49b4e055b3f23aa95248d">00111</a> <span class="keyword">static</span> xcb_window_t <a class="code" href="a00075.html#a12a31f7912e49b4e055b3f23aa95248d">open_input_window</a>(xcb_connection_t *conn, <a class="code" href="a00020.html" title="Stores a rectangle, for example the size of a window, the child window etc.">Rect</a> screen_rect, uint32_t width, uint32_t height) {
<a name="l00112"></a>00112         xcb_window_t <a class="code" href="a00071.html#a768f07da9e11ab88732a5c550ff49257">root</a> = xcb_setup_roots_iterator(xcb_get_setup(conn)).data-&gt;root;
<a name="l00113"></a>00113         xcb_window_t win = xcb_generate_id(conn);
<a name="l00114"></a>00114 
<a name="l00115"></a>00115         uint32_t mask = 0;
<a name="l00116"></a>00116         uint32_t values[2];
<a name="l00117"></a>00117 
<a name="l00118"></a>00118         mask |= XCB_CW_BACK_PIXEL;
<a name="l00119"></a>00119         values[0] = 0;
<a name="l00120"></a>00120 
<a name="l00121"></a>00121         mask |= XCB_CW_OVERRIDE_REDIRECT;
<a name="l00122"></a>00122         values[1] = 1;
<a name="l00123"></a>00123 
<a name="l00124"></a>00124         <span class="comment">/* center each popup on the specified screen */</span>
<a name="l00125"></a>00125         uint32_t x = screen_rect.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a> + ((screen_rect.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a> / 2) - (width / 2)),
<a name="l00126"></a>00126                  <a class="code" href="a00068.html#a16e56e533e1eb98fda15e06fdec03da6">y</a> = screen_rect.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a> + ((screen_rect.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a> / 2) - (height / 2));
<a name="l00127"></a>00127 
<a name="l00128"></a>00128         xcb_create_window(conn,
<a name="l00129"></a>00129                         XCB_COPY_FROM_PARENT,
<a name="l00130"></a>00130                         win, <span class="comment">/* the window id */</span>
<a name="l00131"></a>00131                         root, <span class="comment">/* parent == root */</span>
<a name="l00132"></a>00132                         x, <a class="code" href="a00068.html#a16e56e533e1eb98fda15e06fdec03da6">y</a>, width, height, <span class="comment">/* dimensions */</span>
<a name="l00133"></a>00133                         0, <span class="comment">/* border = 0, we draw our own */</span>
<a name="l00134"></a>00134                         XCB_WINDOW_CLASS_INPUT_OUTPUT,
<a name="l00135"></a>00135                         XCB_WINDOW_CLASS_COPY_FROM_PARENT, <span class="comment">/* copy visual from parent */</span>
<a name="l00136"></a>00136                         mask,
<a name="l00137"></a>00137                         values);
<a name="l00138"></a>00138 
<a name="l00139"></a>00139         <span class="comment">/* Map the window (= make it visible) */</span>
<a name="l00140"></a>00140         xcb_map_window(conn, win);
<a name="l00141"></a>00141 
<a name="l00142"></a>00142         <span class="keywordflow">return</span> win;
<a name="l00143"></a>00143 }
<a name="l00144"></a>00144 
<a name="l00145"></a>00145 <span class="comment">/*</span>
<a name="l00146"></a>00146 <span class="comment"> * Handle signals</span>
<a name="l00147"></a>00147 <span class="comment"> * It creates a window asking the user to restart in-place</span>
<a name="l00148"></a>00148 <span class="comment"> * or exit to generate a core dump</span>
<a name="l00149"></a>00149 <span class="comment"> *</span>
<a name="l00150"></a>00150 <span class="comment"> */</span>
<a name="l00151"></a><a class="code" href="a00075.html#aca29388ca9e7422219ff689ee23d09bc">00151</a> <span class="keywordtype">void</span> <a class="code" href="a00075.html#aca29388ca9e7422219ff689ee23d09bc">handle_signal</a>(<span class="keywordtype">int</span> sig, siginfo_t *info, <span class="keywordtype">void</span> *data) {
<a name="l00152"></a>00152         <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;i3 crashed. SIG: %d\n&quot;</span>, sig);
<a name="l00153"></a>00153 
<a name="l00154"></a>00154         <span class="keyword">struct </span>sigaction action;
<a name="l00155"></a>00155         action.sa_handler = SIG_DFL;
<a name="l00156"></a>00156         sigaction(sig, &amp;action, NULL);
<a name="l00157"></a>00157         <a class="code" href="a00075.html#a2b30b9b043c3efde6d659eb0e579998a">raised_signal</a> = sig;
<a name="l00158"></a>00158 
<a name="l00159"></a>00159         xcb_connection_t *conn = <a class="code" href="a00071.html#ada13c42121d64521629e06e7a5e1db16">global_conn</a>;
<a name="l00160"></a>00160 
<a name="l00161"></a>00161         <span class="comment">/* setup event handler for key presses */</span>
<a name="l00162"></a>00162         xcb_event_handlers_t sig_evenths;
<a name="l00163"></a>00163         memset(&amp;sig_evenths, 0, <span class="keyword">sizeof</span>(xcb_event_handlers_t));
<a name="l00164"></a>00164         xcb_event_handlers_init(conn, &amp;sig_evenths);
<a name="l00165"></a>00165         xcb_event_set_key_press_handler(&amp;sig_evenths, <a class="code" href="a00075.html#afd2deb48146e0d8d84b5bbdbee8b76c7">sig_handle_key_press</a>, NULL);
<a name="l00166"></a>00166 
<a name="l00167"></a>00167         <a class="code" href="a00015.html" title="Data structure for cached font information:font id in X11 (load it once)font height...">i3Font</a> *font = <a class="code" href="a00054.html#a50c1fc0de5343536d542c8349ab7ab0d" title="Loads a font for usage, getting its height.">load_font</a>(conn, <a class="code" href="a00062.html#a4a8dd3a2de125b72d4fe6251a0a271b5">config</a>.<a class="code" href="a00010.html#aff568f0d5ca7a51971f4c3006a842019">font</a>);
<a name="l00168"></a>00168 
<a name="l00169"></a>00169         <span class="comment">/* width and height of the popup window, so that the text fits in */</span>
<a name="l00170"></a>00170         <span class="keywordtype">int</span> crash_text_num = <span class="keyword">sizeof</span>(<a class="code" href="a00075.html#a64d1c56bede447f9de2cccf6326c5ccb">crash_text</a>) / <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>*);
<a name="l00171"></a>00171         <span class="keywordtype">int</span> height = 13 + (crash_text_num * font-&gt;<a class="code" href="a00015.html#a89ceb86bb4ad2694315d846e69893399" title="The height of the font, built from font_ascent + font_descent.">height</a>);
<a name="l00172"></a>00172 
<a name="l00173"></a>00173         <span class="comment">/* calculate width for longest text */</span>
<a name="l00174"></a>00174         <span class="keywordtype">int</span> text_len = strlen(<a class="code" href="a00075.html#a64d1c56bede447f9de2cccf6326c5ccb">crash_text</a>[<a class="code" href="a00075.html#adb8e591cad2f13bf07542bb3b488ac3a">crash_text_longest</a>]);
<a name="l00175"></a>00175         <span class="keywordtype">char</span> *longest_text = <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>(<a class="code" href="a00075.html#a64d1c56bede447f9de2cccf6326c5ccb">crash_text</a>[crash_text_longest], &amp;text_len);
<a name="l00176"></a>00176         <span class="keywordtype">int</span> font_width = <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>(conn, <a class="code" href="a00062.html#a4a8dd3a2de125b72d4fe6251a0a271b5">config</a>.<a class="code" href="a00010.html#aff568f0d5ca7a51971f4c3006a842019">font</a>, longest_text, text_len);
<a name="l00177"></a>00177         <span class="keywordtype">int</span> width = font_width + 20;
<a name="l00178"></a>00178 
<a name="l00179"></a>00179         <span class="comment">/* Open a popup window on each virtual screen */</span>
<a name="l00180"></a>00180         <a class="code" href="a00026.html" title="An Output is a physical output on your graphics driver.">Output</a> *screen;
<a name="l00181"></a>00181         xcb_window_t win;
<a name="l00182"></a>00182         <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(screen, &amp;<a class="code" href="a00073.html#a9fecba0738529e3d9ff0d4fa7c31ffa9">outputs</a>, <a class="code" href="a00073.html#a9fecba0738529e3d9ff0d4fa7c31ffa9">outputs</a>) {
<a name="l00183"></a>00183                 <span class="keywordflow">if</span> (!screen-&gt;<a class="code" href="a00026.html#a7c56e7415ebe0aa040614d1244e2da6b" title="Whether the output is currently active (has a CRTC attached with a valid mode).">active</a>)
<a name="l00184"></a>00184                         <span class="keywordflow">continue</span>;
<a name="l00185"></a>00185                 win = <a class="code" href="a00075.html#a12a31f7912e49b4e055b3f23aa95248d">open_input_window</a>(conn, screen-&gt;<a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>, width, height);
<a name="l00186"></a>00186 
<a name="l00187"></a>00187                 <span class="comment">/* Create pixmap */</span>
<a name="l00188"></a>00188                 <a class="code" href="a00075.html#a81dcec2414a6c7beb665ce0fe5e1eaf6">pixmap</a> = xcb_generate_id(conn);
<a name="l00189"></a>00189                 <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a> = xcb_generate_id(conn);
<a name="l00190"></a>00190                 xcb_create_pixmap(conn, <a class="code" href="a00071.html#a5cc2471a026cd3d2a8800e8ab2c9dcb7">root_depth</a>, <a class="code" href="a00075.html#a81dcec2414a6c7beb665ce0fe5e1eaf6">pixmap</a>, win, width, height);
<a name="l00191"></a>00191                 xcb_create_gc(conn, <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a>, <a class="code" href="a00075.html#a81dcec2414a6c7beb665ce0fe5e1eaf6">pixmap</a>, 0, 0);
<a name="l00192"></a>00192 
<a name="l00193"></a>00193                 <span class="comment">/* Create graphics context */</span>
<a name="l00194"></a>00194                 <a class="code" href="a00079.html#ac20ce6b9cf46f63675e363ac5dc2f24e" title="Changes a single value in the graphic context (so one doesn’t have to define an...">xcb_change_gc_single</a>(conn, <a class="code" href="a00075.html#ab47f85935c9fee430cb37973cf44e490">pixmap_gc</a>, XCB_GC_FONT, font-&gt;<a class="code" href="a00015.html#a34f00fc78328c10986cdebfc3940ee05" title="The xcb-id for the font.">id</a>);
<a name="l00195"></a>00195 
<a name="l00196"></a>00196                 <span class="comment">/* Grab the keyboard to get all input */</span>
<a name="l00197"></a>00197                 xcb_grab_keyboard(conn, <span class="keyword">false</span>, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
<a name="l00198"></a>00198 
<a name="l00199"></a>00199                 <span class="comment">/* Grab the cursor inside the popup */</span>
<a name="l00200"></a>00200                 xcb_grab_pointer(conn, <span class="keyword">false</span>, win, XCB_NONE, XCB_GRAB_MODE_ASYNC,
<a name="l00201"></a>00201                                  XCB_GRAB_MODE_ASYNC, win, XCB_NONE, XCB_CURRENT_TIME);
<a name="l00202"></a>00202 
<a name="l00203"></a>00203                 <a class="code" href="a00075.html#a31aa6fd12baddf237a3aec1a03e5d9a5">sig_draw_window</a>(conn, win, width, height, font-&gt;<a class="code" href="a00015.html#a89ceb86bb4ad2694315d846e69893399" title="The height of the font, built from font_ascent + font_descent.">height</a>);
<a name="l00204"></a>00204                 xcb_flush(conn);
<a name="l00205"></a>00205         }
<a name="l00206"></a>00206 
<a name="l00207"></a>00207         xcb_event_wait_for_event_loop(&amp;sig_evenths);
<a name="l00208"></a>00208 }
<a name="l00209"></a>00209 
<a name="l00210"></a>00210 <span class="comment">/*</span>
<a name="l00211"></a>00211 <span class="comment"> * Setup signal handlers to safely handle SIGSEGV and SIGFPE</span>
<a name="l00212"></a>00212 <span class="comment"> *</span>
<a name="l00213"></a>00213 <span class="comment"> */</span>
<a name="l00214"></a><a class="code" href="a00050.html#ae057b3065391c2db8120a38fe9d805b4">00214</a> <span class="keywordtype">void</span> <a class="code" href="a00075.html#ae057b3065391c2db8120a38fe9d805b4" title="Setup signal handlers to safely handle SIGSEGV and SIGFPE.">setup_signal_handler</a>() {
<a name="l00215"></a>00215         <span class="keyword">struct </span>sigaction action;
<a name="l00216"></a>00216 
<a name="l00217"></a>00217         action.sa_sigaction = <a class="code" href="a00075.html#aca29388ca9e7422219ff689ee23d09bc">handle_signal</a>;
<a name="l00218"></a>00218         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
<a name="l00219"></a>00219         sigemptyset(&amp;action.sa_mask);
<a name="l00220"></a>00220 
<a name="l00221"></a>00221         <span class="keywordflow">if</span> (sigaction(SIGSEGV, &amp;action, NULL) == -1 ||
<a name="l00222"></a>00222             sigaction(SIGFPE, &amp;action, NULL) == -1)
<a name="l00223"></a>00223                 <a class="code" href="a00044.html#a6828c68e0feb4b7fdfe0fc3ba9f3038b">ELOG</a>(<span class="stringliteral">&quot;Could not setup signal handler&quot;</span>);
<a name="l00224"></a>00224 }
</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>