Sophie

Sophie

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

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/xcb.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/xcb.c</h1><a href="a00079.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * vim:ts=8:expandtab</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * i3 - an improved dynamic tiling window manager</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * © 2009-2010 Michael Stapelberg and contributors</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * See file LICENSE for license information.</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * xcb.c: Helper functions for easier usage of XCB</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;stdint.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;xcb/xcb.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;xcb/xcb_keysyms.h&gt;</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;<a class="code" href="a00041.html">i3.h</a>&quot;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &quot;<a class="code" href="a00052.html">util.h</a>&quot;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &quot;<a class="code" href="a00054.html">xcb.h</a>&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &quot;<a class="code" href="a00044.html">log.h</a>&quot;</span>
<a name="l00025"></a>00025 
<a name="l00026"></a><a class="code" href="a00079.html#aba321386159b0e7044414c644e0a4d90">00026</a> <a class="code" href="a00047.html#a4abce769a262e090c1f601605b9d6c76">TAILQ_HEAD</a>(cached_fonts_head, <a class="code" href="a00015.html" title="Data structure for cached font information:font id in X11 (load it once)font height...">Font</a>) cached_fonts = <a class="code" href="a00047.html#ac269df7d4126ed9885156cbad2cbf8af">TAILQ_HEAD_INITIALIZER</a>(cached_fonts);
<a name="l00027"></a>00027 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> xcb_numlock_mask;
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="comment">/*</span>
<a name="l00030"></a>00030 <span class="comment"> * Loads a font for usage, getting its height. This function is used very often, so it</span>
<a name="l00031"></a>00031 <span class="comment"> * maintains a cache.</span>
<a name="l00032"></a>00032 <span class="comment"> *</span>
<a name="l00033"></a>00033 <span class="comment"> */</span>
<a name="l00034"></a>00034 <a class="code" href="a00015.html" title="Data structure for cached font information:font id in X11 (load it once)font height...">i3Font</a> *<a class="code" href="a00054.html#a50c1fc0de5343536d542c8349ab7ab0d" title="Loads a font for usage, getting its height.">load_font</a>(xcb_connection_t *conn, const <span class="keywordtype">char</span> *pattern) {
<a name="l00035"></a>00035         <span class="comment">/* Check if we got the font cached */</span>
<a name="l00036"></a>00036         <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 name="l00037"></a>00037         <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(font, &amp;cached_fonts, fonts)
<a name="l00038"></a>00038                 <span class="keywordflow">if</span> (strcmp(font-&gt;<a class="code" href="a00015.html#a31ddf56d9c371b683e7bd0b9b64e1060" title="A copy of the pattern to build a cache.">pattern</a>, pattern) == 0)
<a name="l00039"></a>00039                         <span class="keywordflow">return</span> font;
<a name="l00040"></a>00040 
<a name="l00041"></a>00041         <a class="code" href="a00015.html" title="Data structure for cached font information:font id in X11 (load it once)font height...">i3Font</a> *<span class="keyword">new</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="keyword">sizeof</span>(<a class="code" href="a00015.html" title="Data structure for cached font information:font id in X11 (load it once)font height...">i3Font</a>));
<a name="l00042"></a>00042         xcb_void_cookie_t font_cookie;
<a name="l00043"></a>00043         xcb_list_fonts_with_info_cookie_t info_cookie;
<a name="l00044"></a>00044 
<a name="l00045"></a>00045         <span class="comment">/* Send all our requests first */</span>
<a name="l00046"></a>00046         <span class="keyword">new</span>-&gt;id = xcb_generate_id(conn);
<a name="l00047"></a>00047         font_cookie = xcb_open_font_checked(conn, new-&gt;id, strlen(pattern), pattern);
<a name="l00048"></a>00048         info_cookie = xcb_list_fonts_with_info(conn, 1, strlen(pattern), pattern);
<a name="l00049"></a>00049 
<a name="l00050"></a>00050         <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>(conn, font_cookie, <span class="stringliteral">&quot;Could not open font&quot;</span>);
<a name="l00051"></a>00051 
<a name="l00052"></a>00052         <span class="comment">/* Get information (height/name) for this font */</span>
<a name="l00053"></a>00053         xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(conn, info_cookie, NULL);
<a name="l00054"></a>00054         <a class="code" href="a00052.html#ad484926a44f04ac0640b81561442091a">exit_if_null</a>(reply, <span class="stringliteral">&quot;Could not load font \&quot;%s\&quot;\n&quot;</span>, pattern);
<a name="l00055"></a>00055 
<a name="l00056"></a>00056         <span class="keywordflow">if</span> (asprintf(&amp;(new-&gt;name), <span class="stringliteral">&quot;%.*s&quot;</span>, xcb_list_fonts_with_info_name_length(reply),
<a name="l00057"></a>00057                                            xcb_list_fonts_with_info_name(reply)) == -1)
<a name="l00058"></a>00058                 <a class="code" href="a00052.html#a0b2164ee75646f16a7388a36e6800c35">die</a>(<span class="stringliteral">&quot;asprintf() failed\n&quot;</span>);
<a name="l00059"></a>00059         <span class="keyword">new</span>-&gt;pattern = <a class="code" href="a00077.html#a11822d1f4b182be3fa03d2a5af536e1a" title="Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there...">sstrdup</a>(pattern);
<a name="l00060"></a>00060         <span class="keyword">new</span>-&gt;height = reply-&gt;font_ascent + reply-&gt;font_descent;
<a name="l00061"></a>00061 
<a name="l00062"></a>00062         <span class="comment">/* Insert into cache */</span>
<a name="l00063"></a>00063         <a class="code" href="a00047.html#a512bee16b46f601078c96c776d2648c3">TAILQ_INSERT_TAIL</a>(&amp;cached_fonts, <span class="keyword">new</span>, fonts);
<a name="l00064"></a>00064 
<a name="l00065"></a>00065         <span class="keywordflow">return</span> <span class="keyword">new</span>;
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067 
<a name="l00068"></a>00068 <span class="comment">/*</span>
<a name="l00069"></a>00069 <span class="comment"> * Returns the colorpixel to use for the given hex color (think of HTML).</span>
<a name="l00070"></a>00070 <span class="comment"> *</span>
<a name="l00071"></a>00071 <span class="comment"> * The hex_color has to start with #, for example #FF00FF.</span>
<a name="l00072"></a>00072 <span class="comment"> *</span>
<a name="l00073"></a>00073 <span class="comment"> * NOTE that get_colorpixel() does _NOT_ check the given color code for validity.</span>
<a name="l00074"></a>00074 <span class="comment"> * This has to be done by the caller.</span>
<a name="l00075"></a>00075 <span class="comment"> *</span>
<a name="l00076"></a>00076 <span class="comment"> */</span>
<a name="l00077"></a><a class="code" href="a00054.html#a0146fe310e31c9509a7a7846aa547c67">00077</a> uint32_t <a class="code" href="a00079.html#a0146fe310e31c9509a7a7846aa547c67" title="Returns the colorpixel to use for the given hex color (think of HTML).">get_colorpixel</a>(xcb_connection_t *conn, <span class="keywordtype">char</span> *hex) {
<a name="l00078"></a>00078         <span class="keywordtype">char</span> strgroups[3][3] = {{hex[1], hex[2], <span class="charliteral">&#39;\0&#39;</span>},
<a name="l00079"></a>00079                                 {hex[3], hex[4], <span class="charliteral">&#39;\0&#39;</span>},
<a name="l00080"></a>00080                                 {hex[5], hex[6], <span class="charliteral">&#39;\0&#39;</span>}};
<a name="l00081"></a>00081         uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
<a name="l00082"></a>00082                              (strtol(strgroups[1], NULL, 16)),
<a name="l00083"></a>00083                              (strtol(strgroups[2], NULL, 16))};
<a name="l00084"></a>00084 
<a name="l00085"></a>00085         <span class="keywordflow">return</span> (rgb16[0] &lt;&lt; 16) + (rgb16[1] &lt;&lt; 8) + rgb16[2];
<a name="l00086"></a>00086 }
<a name="l00087"></a>00087 
<a name="l00088"></a>00088 <span class="comment">/*</span>
<a name="l00089"></a>00089 <span class="comment"> * Convenience wrapper around xcb_create_window which takes care of depth, generating an ID and checking</span>
<a name="l00090"></a>00090 <span class="comment"> * for errors.</span>
<a name="l00091"></a>00091 <span class="comment"> *</span>
<a name="l00092"></a>00092 <span class="comment"> */</span>
<a name="l00093"></a><a class="code" href="a00054.html#a7ab69e6509e1095ede3d98ab760d0e61">00093</a> xcb_window_t <a class="code" href="a00079.html#a1c6bb71a9f8e0501e2228dd3dca3bd6a" title="Convenience wrapper around xcb_create_window which takes care of depth, generating...">create_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> dims, uint16_t window_class, <span class="keywordtype">int</span> cursor,
<a name="l00094"></a>00094                            <span class="keywordtype">bool</span> map, uint32_t mask, uint32_t *values) {
<a name="l00095"></a>00095         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="l00096"></a>00096         xcb_window_t result = xcb_generate_id(conn);
<a name="l00097"></a>00097         xcb_cursor_t cursor_id = xcb_generate_id(conn);
<a name="l00098"></a>00098 
<a name="l00099"></a>00099         <span class="comment">/* If the window class is XCB_WINDOW_CLASS_INPUT_ONLY, depth has to be 0 */</span>
<a name="l00100"></a>00100         uint16_t depth = (window_class == XCB_WINDOW_CLASS_INPUT_ONLY ? 0 : XCB_COPY_FROM_PARENT);
<a name="l00101"></a>00101 
<a name="l00102"></a>00102         xcb_create_window(conn,
<a name="l00103"></a>00103                           depth,
<a name="l00104"></a>00104                           result, <span class="comment">/* the window id */</span>
<a name="l00105"></a>00105                           root, <span class="comment">/* parent == root */</span>
<a name="l00106"></a>00106                           dims.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a>, dims.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a>, dims.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a>, dims.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a>, <span class="comment">/* dimensions */</span>
<a name="l00107"></a>00107                           0, <span class="comment">/* border = 0, we draw our own */</span>
<a name="l00108"></a>00108                           window_class,
<a name="l00109"></a>00109                           XCB_WINDOW_CLASS_COPY_FROM_PARENT, <span class="comment">/* copy visual from parent */</span>
<a name="l00110"></a>00110                           mask,
<a name="l00111"></a>00111                           values);
<a name="l00112"></a>00112 
<a name="l00113"></a>00113         <span class="comment">/* Set the cursor */</span>
<a name="l00114"></a>00114         <a class="code" href="a00015.html" title="Data structure for cached font information:font id in X11 (load it once)font height...">i3Font</a> *cursor_font = <a class="code" href="a00054.html#a50c1fc0de5343536d542c8349ab7ab0d" title="Loads a font for usage, getting its height.">load_font</a>(conn, <span class="stringliteral">&quot;cursor&quot;</span>);
<a name="l00115"></a>00115         xcb_create_glyph_cursor(conn, cursor_id, cursor_font-&gt;<a class="code" href="a00015.html#a34f00fc78328c10986cdebfc3940ee05" title="The xcb-id for the font.">id</a>, cursor_font-&gt;<a class="code" href="a00015.html#a34f00fc78328c10986cdebfc3940ee05" title="The xcb-id for the font.">id</a>,
<a name="l00116"></a>00116                         (cursor == -1 ? <a class="code" href="a00054.html#ada5e89d9bddd5e5feff900639db2e208" title="This is the equivalent of XC_left_ptr.">XCB_CURSOR_LEFT_PTR</a> : cursor),
<a name="l00117"></a>00117                         (cursor == -1 ? <a class="code" href="a00054.html#ada5e89d9bddd5e5feff900639db2e208" title="This is the equivalent of XC_left_ptr.">XCB_CURSOR_LEFT_PTR</a> : cursor) + 1,
<a name="l00118"></a>00118                         0, 0, 0, 65535, 65535, 65535);
<a name="l00119"></a>00119         xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, &amp;cursor_id);
<a name="l00120"></a>00120         xcb_free_cursor(conn, cursor_id);
<a name="l00121"></a>00121 
<a name="l00122"></a>00122         <span class="comment">/* Map the window (= make it visible) */</span>
<a name="l00123"></a>00123         <span class="keywordflow">if</span> (map)
<a name="l00124"></a>00124                 xcb_map_window(conn, result);
<a name="l00125"></a>00125 
<a name="l00126"></a>00126         <span class="keywordflow">return</span> result;
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128 
<a name="l00129"></a>00129 <span class="comment">/*</span>
<a name="l00130"></a>00130 <span class="comment"> * Changes a single value in the graphic context (so one doesn’t have to define an array of values)</span>
<a name="l00131"></a>00131 <span class="comment"> *</span>
<a name="l00132"></a>00132 <span class="comment"> */</span>
<a name="l00133"></a><a class="code" href="a00054.html#ac20ce6b9cf46f63675e363ac5dc2f24e">00133</a> <span class="keywordtype">void</span> <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>(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value) {
<a name="l00134"></a>00134         xcb_change_gc(conn, gc, mask, &amp;value);
<a name="l00135"></a>00135 }
<a name="l00136"></a>00136 
<a name="l00137"></a>00137 <span class="comment">/*</span>
<a name="l00138"></a>00138 <span class="comment"> * Draws a line from x,y to to_x,to_y using the given color</span>
<a name="l00139"></a>00139 <span class="comment"> *</span>
<a name="l00140"></a>00140 <span class="comment"> */</span>
<a name="l00141"></a><a class="code" href="a00054.html#aceb7b1de1af10ea8def35d48a1b0caad">00141</a> <span class="keywordtype">void</span> <a class="code" href="a00079.html#aceb7b1de1af10ea8def35d48a1b0caad" title="Draws a line from x,y to to_x,to_y using the given color.">xcb_draw_line</a>(xcb_connection_t *conn, xcb_drawable_t drawable, xcb_gcontext_t gc,
<a name="l00142"></a>00142                    uint32_t colorpixel, uint32_t x, uint32_t <a class="code" href="a00068.html#a16e56e533e1eb98fda15e06fdec03da6">y</a>, uint32_t to_x, uint32_t to_y) {
<a name="l00143"></a>00143         <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, gc, XCB_GC_FOREGROUND, colorpixel);
<a name="l00144"></a>00144         xcb_point_t points[] = {{x, y}, {to_x, to_y}};
<a name="l00145"></a>00145         xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, drawable, gc, 2, points);
<a name="l00146"></a>00146 }
<a name="l00147"></a>00147 
<a name="l00148"></a>00148 <span class="comment">/*</span>
<a name="l00149"></a>00149 <span class="comment"> * Draws a rectangle from x,y with width,height using the given color</span>
<a name="l00150"></a>00150 <span class="comment"> *</span>
<a name="l00151"></a>00151 <span class="comment"> */</span>
<a name="l00152"></a><a class="code" href="a00054.html#ac2b163cc3d76bdec224a1ce5c7ac9c6d">00152</a> <span class="keywordtype">void</span> <a class="code" href="a00079.html#ac2b163cc3d76bdec224a1ce5c7ac9c6d" title="Draws a rectangle from x,y with width,height using the given color.">xcb_draw_rect</a>(xcb_connection_t *conn, xcb_drawable_t drawable, xcb_gcontext_t gc,
<a name="l00153"></a>00153                    uint32_t colorpixel, uint32_t x, uint32_t <a class="code" href="a00068.html#a16e56e533e1eb98fda15e06fdec03da6">y</a>, uint32_t width, uint32_t height) {
<a name="l00154"></a>00154         <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, gc, XCB_GC_FOREGROUND, colorpixel);
<a name="l00155"></a>00155         xcb_rectangle_t <a class="code" href="a00023.html#ac42bcee20d4f77f4ecbdec1dbb616a4f">rect</a> = {x, y, width, height};
<a name="l00156"></a>00156         xcb_poly_fill_rectangle(conn, drawable, gc, 1, &amp;rect);
<a name="l00157"></a>00157 }
<a name="l00158"></a>00158 
<a name="l00159"></a>00159 <span class="comment">/*</span>
<a name="l00160"></a>00160 <span class="comment"> * Generates a configure_notify event and sends it to the given window</span>
<a name="l00161"></a>00161 <span class="comment"> * Applications need this to think they’ve configured themselves correctly.</span>
<a name="l00162"></a>00162 <span class="comment"> * The truth is, however, that we will manage them.</span>
<a name="l00163"></a>00163 <span class="comment"> *</span>
<a name="l00164"></a>00164 <span class="comment"> */</span>
<a name="l00165"></a><a class="code" href="a00054.html#a164801596691fe72d4e2e2f1b8b3cee1">00165</a> <span class="keywordtype">void</span> <a class="code" href="a00079.html#a164801596691fe72d4e2e2f1b8b3cee1" title="Generates a configure_notify event and sends it to the given window Applications...">fake_configure_notify</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> r, xcb_window_t <a class="code" href="a00023.html#aa10861a9e5d4859d70275b462acfcd24">window</a>) {
<a name="l00166"></a>00166         xcb_configure_notify_event_t generated_event;
<a name="l00167"></a>00167 
<a name="l00168"></a>00168         generated_event.event = window;
<a name="l00169"></a>00169         generated_event.window = window;
<a name="l00170"></a>00170         generated_event.response_type = XCB_CONFIGURE_NOTIFY;
<a name="l00171"></a>00171 
<a name="l00172"></a>00172         generated_event.x = r.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a>;
<a name="l00173"></a>00173         generated_event.y = r.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a>;
<a name="l00174"></a>00174         generated_event.width = r.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a>;
<a name="l00175"></a>00175         generated_event.height = r.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a>;
<a name="l00176"></a>00176 
<a name="l00177"></a>00177         generated_event.border_width = 0;
<a name="l00178"></a>00178         generated_event.above_sibling = XCB_NONE;
<a name="l00179"></a>00179         generated_event.override_redirect = <span class="keyword">false</span>;
<a name="l00180"></a>00180 
<a name="l00181"></a>00181         xcb_send_event(conn, <span class="keyword">false</span>, window, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (<span class="keywordtype">char</span>*)&amp;generated_event);
<a name="l00182"></a>00182         xcb_flush(conn);
<a name="l00183"></a>00183 }
<a name="l00184"></a>00184 
<a name="l00185"></a>00185 <span class="comment">/*</span>
<a name="l00186"></a>00186 <span class="comment"> * Generates a configure_notify_event with absolute coordinates (relative to the X root</span>
<a name="l00187"></a>00187 <span class="comment"> * window, not to the client’s frame) for the given client.</span>
<a name="l00188"></a>00188 <span class="comment"> *</span>
<a name="l00189"></a>00189 <span class="comment"> */</span>
<a name="l00190"></a><a class="code" href="a00054.html#a66ff853f6bedca4b4c142f3b7561b189">00190</a> <span class="keywordtype">void</span> <a class="code" href="a00079.html#a66ff853f6bedca4b4c142f3b7561b189" title="Generates a configure_notify_event with absolute coordinates (relative to the X root...">fake_absolute_configure_notify</a>(xcb_connection_t *conn, <a class="code" href="a00007.html" title="A client is X11-speak for a window.">Client</a> *client) {
<a name="l00191"></a>00191         <a class="code" href="a00020.html" title="Stores a rectangle, for example the size of a window, the child window etc.">Rect</a> absolute;
<a name="l00192"></a>00192 
<a name="l00193"></a>00193         absolute.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a> = client-&gt;<a class="code" href="a00007.html#aea76187592ae1a87eb8bb1af77af62d4" title="x, y, width, height of the frame">rect</a>.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a> + client-&gt;<a class="code" href="a00007.html#a694f6f127e048521451f931174a6e140" title="x, y, width, height of the child (relative to its frame)">child_rect</a>.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a>;
<a name="l00194"></a>00194         absolute.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a> = client-&gt;<a class="code" href="a00007.html#aea76187592ae1a87eb8bb1af77af62d4" title="x, y, width, height of the frame">rect</a>.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a> + client-&gt;<a class="code" href="a00007.html#a694f6f127e048521451f931174a6e140" title="x, y, width, height of the child (relative to its frame)">child_rect</a>.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a>;
<a name="l00195"></a>00195         absolute.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a> = client-&gt;<a class="code" href="a00007.html#a694f6f127e048521451f931174a6e140" title="x, y, width, height of the child (relative to its frame)">child_rect</a>.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a>;
<a name="l00196"></a>00196         absolute.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a> = client-&gt;<a class="code" href="a00007.html#a694f6f127e048521451f931174a6e140" title="x, y, width, height of the child (relative to its frame)">child_rect</a>.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a>;
<a name="l00197"></a>00197 
<a name="l00198"></a>00198         <a class="code" href="a00079.html#a164801596691fe72d4e2e2f1b8b3cee1" title="Generates a configure_notify event and sends it to the given window Applications...">fake_configure_notify</a>(conn, absolute, client-&gt;<a class="code" href="a00007.html#afba312b946fa74727ce619a33f8f28aa" title="The client’s window.">child</a>);
<a name="l00199"></a>00199 }
<a name="l00200"></a>00200 
<a name="l00201"></a>00201 <span class="comment">/*</span>
<a name="l00202"></a>00202 <span class="comment"> * Finds out which modifier mask is the one for numlock, as the user may change this.</span>
<a name="l00203"></a>00203 <span class="comment"> *</span>
<a name="l00204"></a>00204 <span class="comment"> */</span>
<a name="l00205"></a><a class="code" href="a00054.html#aeae86e9fc76e08fd43f142de4d11bba0">00205</a> <span class="keywordtype">void</span> <a class="code" href="a00079.html#aeae86e9fc76e08fd43f142de4d11bba0" title="Finds out which modifier mask is the one for numlock, as the user may change this...">xcb_get_numlock_mask</a>(xcb_connection_t *conn) {
<a name="l00206"></a>00206         xcb_key_symbols_t *<a class="code" href="a00071.html#a5cc0138ae2cf3bbb63a7cae907620797">keysyms</a>;
<a name="l00207"></a>00207         xcb_get_modifier_mapping_cookie_t cookie;
<a name="l00208"></a>00208         xcb_get_modifier_mapping_reply_t *reply;
<a name="l00209"></a>00209         xcb_keycode_t *modmap;
<a name="l00210"></a>00210         <span class="keywordtype">int</span> mask, i;
<a name="l00211"></a>00211         <span class="keyword">const</span> <span class="keywordtype">int</span> masks[8] = { XCB_MOD_MASK_SHIFT,
<a name="l00212"></a>00212                                XCB_MOD_MASK_LOCK,
<a name="l00213"></a>00213                                XCB_MOD_MASK_CONTROL,
<a name="l00214"></a>00214                                XCB_MOD_MASK_1,
<a name="l00215"></a>00215                                XCB_MOD_MASK_2,
<a name="l00216"></a>00216                                XCB_MOD_MASK_3,
<a name="l00217"></a>00217                                XCB_MOD_MASK_4,
<a name="l00218"></a>00218                                XCB_MOD_MASK_5 };
<a name="l00219"></a>00219 
<a name="l00220"></a>00220         <span class="comment">/* Request the modifier map */</span>
<a name="l00221"></a>00221         cookie = xcb_get_modifier_mapping_unchecked(conn);
<a name="l00222"></a>00222 
<a name="l00223"></a>00223         <span class="comment">/* Get the keysymbols */</span>
<a name="l00224"></a>00224         keysyms = xcb_key_symbols_alloc(conn);
<a name="l00225"></a>00225 
<a name="l00226"></a>00226         <span class="keywordflow">if</span> ((reply = xcb_get_modifier_mapping_reply(conn, cookie, NULL)) == NULL) {
<a name="l00227"></a>00227                 xcb_key_symbols_free(keysyms);
<a name="l00228"></a>00228                 <span class="keywordflow">return</span>;
<a name="l00229"></a>00229         }
<a name="l00230"></a>00230 
<a name="l00231"></a>00231         modmap = xcb_get_modifier_mapping_keycodes(reply);
<a name="l00232"></a>00232 
<a name="l00233"></a>00233         <span class="comment">/* Get the keycode for numlock */</span>
<a name="l00234"></a>00234 <span class="preprocessor">#ifdef OLD_XCB_KEYSYMS_API</span>
<a name="l00235"></a>00235 <span class="preprocessor"></span>        xcb_keycode_t numlock = xcb_key_symbols_get_keycode(keysyms, <a class="code" href="a00054.html#a317f6b3487405530a05621915ee75230">XCB_NUM_LOCK</a>);
<a name="l00236"></a>00236 <span class="preprocessor">#else</span>
<a name="l00237"></a>00237 <span class="preprocessor"></span>        <span class="comment">/* For now, we only use the first keysymbol. */</span>
<a name="l00238"></a>00238         xcb_keycode_t *numlock_syms = xcb_key_symbols_get_keycode(keysyms, <a class="code" href="a00054.html#a317f6b3487405530a05621915ee75230">XCB_NUM_LOCK</a>);
<a name="l00239"></a>00239         <span class="keywordflow">if</span> (numlock_syms == NULL)
<a name="l00240"></a>00240                 <span class="keywordflow">return</span>;
<a name="l00241"></a>00241         xcb_keycode_t numlock = *numlock_syms;
<a name="l00242"></a>00242         free(numlock_syms);
<a name="l00243"></a>00243 <span class="preprocessor">#endif</span>
<a name="l00244"></a>00244 <span class="preprocessor"></span>
<a name="l00245"></a>00245         <span class="comment">/* Check all modifiers (Mod1-Mod5, Shift, Control, Lock) */</span>
<a name="l00246"></a>00246         <span class="keywordflow">for</span> (mask = 0; mask &lt; 8; mask++)
<a name="l00247"></a>00247                 <span class="keywordflow">for</span> (i = 0; i &lt; reply-&gt;keycodes_per_modifier; i++)
<a name="l00248"></a>00248                         <span class="keywordflow">if</span> (modmap[(mask * reply-&gt;keycodes_per_modifier) + i] == numlock)
<a name="l00249"></a>00249                                 <a class="code" href="a00054.html#ac430ae06cbf6f5ef252c9ebfca47e644">xcb_numlock_mask</a> = masks[mask];
<a name="l00250"></a>00250 
<a name="l00251"></a>00251         xcb_key_symbols_free(keysyms);
<a name="l00252"></a>00252         free(reply);
<a name="l00253"></a>00253 }
<a name="l00254"></a>00254 
<a name="l00255"></a>00255 <span class="comment">/*</span>
<a name="l00256"></a>00256 <span class="comment"> * Raises the given window (typically client-&gt;frame) above all other windows</span>
<a name="l00257"></a>00257 <span class="comment"> *</span>
<a name="l00258"></a>00258 <span class="comment"> */</span>
<a name="l00259"></a><a class="code" href="a00054.html#a6ea5ab6082e87ce76340a38034f7b513">00259</a> <span class="keywordtype">void</span> <a class="code" href="a00079.html#a6ea5ab6082e87ce76340a38034f7b513" title="Raises the given window (typically client-&amp;gt;frame) above all other windows.">xcb_raise_window</a>(xcb_connection_t *conn, xcb_window_t <a class="code" href="a00023.html#aa10861a9e5d4859d70275b462acfcd24">window</a>) {
<a name="l00260"></a>00260         uint32_t values[] = { XCB_STACK_MODE_ABOVE };
<a name="l00261"></a>00261         xcb_configure_window(conn, window, XCB_CONFIG_WINDOW_STACK_MODE, values);
<a name="l00262"></a>00262 }
<a name="l00263"></a>00263 
<a name="l00264"></a>00264 <span class="comment">/*</span>
<a name="l00265"></a>00265 <span class="comment"> *</span>
<a name="l00266"></a>00266 <span class="comment"> * Prepares the given Cached_Pixmap for usage (checks whether the size of the</span>
<a name="l00267"></a>00267 <span class="comment"> * object this pixmap is related to (e.g. a window) has changed and re-creates</span>
<a name="l00268"></a>00268 <span class="comment"> * the pixmap if so).</span>
<a name="l00269"></a>00269 <span class="comment"> *</span>
<a name="l00270"></a>00270 <span class="comment"> */</span>
<a name="l00271"></a><a class="code" href="a00054.html#a22762f8bf69c7dcfdafac47e5e39695a">00271</a> <span class="keywordtype">void</span> <a class="code" href="a00079.html#a22762f8bf69c7dcfdafac47e5e39695a" title="Prepares the given Cached_Pixmap for usage (checks whether the size of the object...">cached_pixmap_prepare</a>(xcb_connection_t *conn, <span class="keyword">struct</span> <a class="code" href="a00004.html">Cached_Pixmap</a> *<a class="code" href="a00075.html#a81dcec2414a6c7beb665ce0fe5e1eaf6">pixmap</a>) {
<a name="l00272"></a>00272         <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;preparing pixmap\n&quot;</span>);
<a name="l00273"></a>00273 
<a name="l00274"></a>00274         <span class="comment">/* If the Rect did not change, the pixmap does not need to be recreated */</span>
<a name="l00275"></a>00275         <span class="keywordflow">if</span> (memcmp(&amp;(pixmap-&gt;<a class="code" href="a00004.html#a5e379c39a6883006c3d07af1d77aad4c">rect</a>), pixmap-&gt;<a class="code" href="a00004.html#a34c59c8ce74f3d808ec0a045b138be39">referred_rect</a>, <span class="keyword">sizeof</span>(<a class="code" href="a00020.html" title="Stores a rectangle, for example the size of a window, the child window etc.">Rect</a>)) == 0)
<a name="l00276"></a>00276                 <span class="keywordflow">return</span>;
<a name="l00277"></a>00277 
<a name="l00278"></a>00278         memcpy(&amp;(pixmap-&gt;<a class="code" href="a00004.html#a5e379c39a6883006c3d07af1d77aad4c">rect</a>), pixmap-&gt;<a class="code" href="a00004.html#a34c59c8ce74f3d808ec0a045b138be39">referred_rect</a>, <span class="keyword">sizeof</span>(<a class="code" href="a00020.html" title="Stores a rectangle, for example the size of a window, the child window etc.">Rect</a>));
<a name="l00279"></a>00279 
<a name="l00280"></a>00280         <span class="keywordflow">if</span> (pixmap-&gt;<a class="code" href="a00004.html#a75c370b918b9f963d6430ba07e7c56bf">id</a> == 0 || pixmap-&gt;<a class="code" href="a00004.html#a1930bbf9d5570906ace6d8aaeea0cbf1">gc</a> == 0) {
<a name="l00281"></a>00281                 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;Creating new pixmap...\n&quot;</span>);
<a name="l00282"></a>00282                 pixmap-&gt;<a class="code" href="a00004.html#a75c370b918b9f963d6430ba07e7c56bf">id</a> = xcb_generate_id(conn);
<a name="l00283"></a>00283                 pixmap-&gt;<a class="code" href="a00004.html#a1930bbf9d5570906ace6d8aaeea0cbf1">gc</a> = xcb_generate_id(conn);
<a name="l00284"></a>00284         } <span class="keywordflow">else</span> {
<a name="l00285"></a>00285                 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">&quot;Re-creating this pixmap...\n&quot;</span>);
<a name="l00286"></a>00286                 xcb_free_gc(conn, pixmap-&gt;<a class="code" href="a00004.html#a1930bbf9d5570906ace6d8aaeea0cbf1">gc</a>);
<a name="l00287"></a>00287                 xcb_free_pixmap(conn, pixmap-&gt;<a class="code" href="a00004.html#a75c370b918b9f963d6430ba07e7c56bf">id</a>);
<a name="l00288"></a>00288         }
<a name="l00289"></a>00289 
<a name="l00290"></a>00290         xcb_create_pixmap(conn, <a class="code" href="a00071.html#a5cc2471a026cd3d2a8800e8ab2c9dcb7">root_depth</a>, pixmap-&gt;<a class="code" href="a00004.html#a75c370b918b9f963d6430ba07e7c56bf">id</a>,
<a name="l00291"></a>00291                           pixmap-&gt;<a class="code" href="a00004.html#ad05fd81000b6ee526f8a737b043edb8a">referred_drawable</a>, pixmap-&gt;<a class="code" href="a00004.html#a5e379c39a6883006c3d07af1d77aad4c">rect</a>.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a>, pixmap-&gt;<a class="code" href="a00004.html#a5e379c39a6883006c3d07af1d77aad4c">rect</a>.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a>);
<a name="l00292"></a>00292 
<a name="l00293"></a>00293         xcb_create_gc(conn, pixmap-&gt;<a class="code" href="a00004.html#a1930bbf9d5570906ace6d8aaeea0cbf1">gc</a>, pixmap-&gt;<a class="code" href="a00004.html#a75c370b918b9f963d6430ba07e7c56bf">id</a>, 0, 0);
<a name="l00294"></a>00294 }
<a name="l00295"></a>00295 
<a name="l00296"></a>00296 <span class="comment">/*</span>
<a name="l00297"></a>00297 <span class="comment"> * Query the width of the given text (16-bit characters, UCS) with given real</span>
<a name="l00298"></a>00298 <span class="comment"> * length (amount of glyphs) using the given font.</span>
<a name="l00299"></a>00299 <span class="comment"> *</span>
<a name="l00300"></a>00300 <span class="comment"> */</span>
<a name="l00301"></a><a class="code" href="a00054.html#a01397b2251980ca02d24194293fc79d0">00301</a> <span class="keywordtype">int</span> <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>(xcb_connection_t *conn, <span class="keyword">const</span> <span class="keywordtype">char</span> *font_pattern, <span class="keywordtype">char</span> *text, <span class="keywordtype">int</span> length) {
<a name="l00302"></a>00302         <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, font_pattern);
<a name="l00303"></a>00303 
<a name="l00304"></a>00304         xcb_query_text_extents_cookie_t cookie;
<a name="l00305"></a>00305         xcb_query_text_extents_reply_t *reply;
<a name="l00306"></a>00306         xcb_generic_error_t *error;
<a name="l00307"></a>00307         <span class="keywordtype">int</span> width;
<a name="l00308"></a>00308 
<a name="l00309"></a>00309         cookie = xcb_query_text_extents(conn, font-&gt;<a class="code" href="a00015.html#a34f00fc78328c10986cdebfc3940ee05" title="The xcb-id for the font.">id</a>, length, (xcb_char2b_t*)text);
<a name="l00310"></a>00310         <span class="keywordflow">if</span> ((reply = xcb_query_text_extents_reply(conn, cookie, &amp;error)) == NULL) {
<a name="l00311"></a>00311                 <a class="code" href="a00044.html#a6828c68e0feb4b7fdfe0fc3ba9f3038b">ELOG</a>(<span class="stringliteral">&quot;Could not get text extents (X error code %d)\n&quot;</span>,
<a name="l00312"></a>00312                      error-&gt;error_code);
<a name="l00313"></a>00313                 <span class="comment">/* We return the rather safe guess of 7 pixels, because a</span>
<a name="l00314"></a>00314 <span class="comment">                 * rendering error is better than a crash. Plus, the user will</span>
<a name="l00315"></a>00315 <span class="comment">                 * see the error in his log. */</span>
<a name="l00316"></a>00316                 <span class="keywordflow">return</span> 7;
<a name="l00317"></a>00317         }
<a name="l00318"></a>00318 
<a name="l00319"></a>00319         width = reply-&gt;overall_width;
<a name="l00320"></a>00320         free(reply);
<a name="l00321"></a>00321         <span class="keywordflow">return</span> width;
<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"> * Configures the given window to have the size/position specified by given rect</span>
<a name="l00326"></a>00326 <span class="comment"> *</span>
<a name="l00327"></a>00327 <span class="comment"> */</span>
<a name="l00328"></a><a class="code" href="a00054.html#a7bbb53cdd77036e67c997f0c93e67cef">00328</a> <span class="keywordtype">void</span> <a class="code" href="a00079.html#a7bbb53cdd77036e67c997f0c93e67cef" title="Configures the given window to have the size/position specified by given rect.">xcb_set_window_rect</a>(xcb_connection_t *conn, xcb_window_t <a class="code" href="a00023.html#aa10861a9e5d4859d70275b462acfcd24">window</a>, <a class="code" href="a00020.html" title="Stores a rectangle, for example the size of a window, the child window etc.">Rect</a> r) {
<a name="l00329"></a>00329         xcb_configure_window(conn, window,
<a name="l00330"></a>00330                              XCB_CONFIG_WINDOW_X |
<a name="l00331"></a>00331                              XCB_CONFIG_WINDOW_Y |
<a name="l00332"></a>00332                              XCB_CONFIG_WINDOW_WIDTH |
<a name="l00333"></a>00333                              XCB_CONFIG_WINDOW_HEIGHT,
<a name="l00334"></a>00334                              &amp;(r.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a>));
<a name="l00335"></a>00335 }
</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>