<!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/xinerama.c Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.2-20100208 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <h1>src/xinerama.c</h1><a href="a00080.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"> * This is LEGACY code (we support RandR, which can do much more than</span> <a name="l00011"></a>00011 <span class="comment"> * Xinerama), but necessary for the poor users of the nVidia binary</span> <a name="l00012"></a>00012 <span class="comment"> * driver which does not support RandR in 2010 *sigh*.</span> <a name="l00013"></a>00013 <span class="comment"> *</span> <a name="l00014"></a>00014 <span class="comment"> */</span> <a name="l00015"></a>00015 <span class="preprocessor">#include <stdio.h></span> <a name="l00016"></a>00016 <span class="preprocessor">#include <stdlib.h></span> <a name="l00017"></a>00017 <span class="preprocessor">#include <string.h></span> <a name="l00018"></a>00018 <a name="l00019"></a>00019 <span class="preprocessor">#include <xcb/xcb.h></span> <a name="l00020"></a>00020 <span class="preprocessor">#include <xcb/xinerama.h></span> <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="a00047.html">queue.h</a>"</span> <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="a00036.html">data.h</a>"</span> <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="a00052.html">util.h</a>"</span> <a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="a00055.html">xinerama.h</a>"</span> <a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="a00053.html">workspace.h</a>"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="a00044.html">log.h</a>"</span> <a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="a00048.html">randr.h</a>"</span> <a name="l00029"></a>00029 <a name="l00030"></a><a class="code" href="a00080.html#a59ff745efdee354cf2bc3dd370fec282">00030</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="a00071.html#a59ff745efdee354cf2bc3dd370fec282">num_screens</a>; <a name="l00031"></a>00031 <a name="l00032"></a>00032 <span class="comment">/*</span> <a name="l00033"></a>00033 <span class="comment"> * Looks in outputs for the Output whose start coordinates are x, y</span> <a name="l00034"></a>00034 <span class="comment"> *</span> <a name="l00035"></a>00035 <span class="comment"> */</span> <a name="l00036"></a><a class="code" href="a00080.html#a6d839fbeabf7798879b865fe1050dd11">00036</a> <span class="keyword">static</span> <a class="code" href="a00026.html" title="An Output is a physical output on your graphics driver.">Output</a> *<a class="code" href="a00080.html#a6d839fbeabf7798879b865fe1050dd11">get_screen_at</a>(<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> <a class="code" href="a00068.html#a16e56e533e1eb98fda15e06fdec03da6">y</a>) { <a name="l00037"></a>00037 <a class="code" href="a00026.html" title="An Output is a physical output on your graphics driver.">Output</a> *output; <a name="l00038"></a>00038 <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(output, &<a class="code" href="a00073.html#a9fecba0738529e3d9ff0d4fa7c31ffa9">outputs</a>, <a class="code" href="a00073.html#a9fecba0738529e3d9ff0d4fa7c31ffa9">outputs</a>) <a name="l00039"></a>00039 <span class="keywordflow">if</span> (output-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a> == x && output-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a> == y) <a name="l00040"></a>00040 <span class="keywordflow">return</span> output; <a name="l00041"></a>00041 <a name="l00042"></a>00042 <span class="keywordflow">return</span> NULL; <a name="l00043"></a>00043 } <a name="l00044"></a>00044 <a name="l00045"></a>00045 <span class="comment">/*</span> <a name="l00046"></a>00046 <span class="comment"> * Gets the Xinerama screens and converts them to virtual Outputs (only one screen for two</span> <a name="l00047"></a>00047 <span class="comment"> * Xinerama screen which are configured in clone mode) in the given screenlist</span> <a name="l00048"></a>00048 <span class="comment"> *</span> <a name="l00049"></a>00049 <span class="comment"> */</span> <a name="l00050"></a><a class="code" href="a00080.html#a6c10a3a62f737a084108860feb421d94">00050</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="a00080.html#a6c10a3a62f737a084108860feb421d94">query_screens</a>(xcb_connection_t *conn) { <a name="l00051"></a>00051 xcb_xinerama_query_screens_reply_t *reply; <a name="l00052"></a>00052 xcb_xinerama_screen_info_t *screen_info; <a name="l00053"></a>00053 <a name="l00054"></a>00054 reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL); <a name="l00055"></a>00055 <span class="keywordflow">if</span> (!reply) { <a name="l00056"></a>00056 <a class="code" href="a00044.html#a6828c68e0feb4b7fdfe0fc3ba9f3038b">ELOG</a>(<span class="stringliteral">"Couldn't get Xinerama screens\n"</span>); <a name="l00057"></a>00057 <span class="keywordflow">return</span>; <a name="l00058"></a>00058 } <a name="l00059"></a>00059 screen_info = xcb_xinerama_query_screens_screen_info(reply); <a name="l00060"></a>00060 <span class="keywordtype">int</span> screens = xcb_xinerama_query_screens_screen_info_length(reply); <a name="l00061"></a>00061 <a name="l00062"></a>00062 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> screen = 0; screen < screens; screen++) { <a name="l00063"></a>00063 <a class="code" href="a00026.html" title="An Output is a physical output on your graphics driver.">Output</a> *s = <a class="code" href="a00080.html#a6d839fbeabf7798879b865fe1050dd11">get_screen_at</a>(screen_info[screen].x_org, screen_info[screen].y_org); <a name="l00064"></a>00064 <span class="keywordflow">if</span> (s != NULL) { <a name="l00065"></a>00065 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Re-used old Xinerama screen %p\n"</span>, s); <a name="l00066"></a>00066 <span class="comment">/* This screen already exists. We use the littlest screen so that the user</span> <a name="l00067"></a>00067 <span class="comment"> can always see the complete workspace */</span> <a name="l00068"></a>00068 s-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a> = <a class="code" href="a00077.html#abd8bbcfabb3ddef2ccaafb9928a37b95">min</a>(s-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a>, screen_info[screen].width); <a name="l00069"></a>00069 s-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a> = <a class="code" href="a00077.html#abd8bbcfabb3ddef2ccaafb9928a37b95">min</a>(s-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a>, screen_info[screen].height); <a name="l00070"></a>00070 } <span class="keywordflow">else</span> { <a name="l00071"></a>00071 s = <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>(<a class="code" href="a00026.html" title="An Output is a physical output on your graphics driver.">Output</a>)); <a name="l00072"></a>00072 asprintf(&(s-><a class="code" href="a00026.html#a4c8b185b15cf45e3ca300cb54b2d4650" title="Name of the output.">name</a>), <span class="stringliteral">"xinerama-%d"</span>, <a class="code" href="a00071.html#a59ff745efdee354cf2bc3dd370fec282">num_screens</a>); <a name="l00073"></a>00073 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Created new Xinerama screen %s (%p)\n"</span>, s-><a class="code" href="a00026.html#a4c8b185b15cf45e3ca300cb54b2d4650" title="Name of the output.">name</a>, s); <a name="l00074"></a>00074 s-><a class="code" href="a00026.html#a7c56e7415ebe0aa040614d1244e2da6b" title="Whether the output is currently active (has a CRTC attached with a valid mode).">active</a> = <span class="keyword">true</span>; <a name="l00075"></a>00075 s-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a> = screen_info[screen].x_org; <a name="l00076"></a>00076 s-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a> = screen_info[screen].y_org; <a name="l00077"></a>00077 s-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a> = screen_info[screen].width; <a name="l00078"></a>00078 s-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a> = screen_info[screen].height; <a name="l00079"></a>00079 <span class="comment">/* We always treat the screen at 0x0 as the primary screen */</span> <a name="l00080"></a>00080 <span class="keywordflow">if</span> (s-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a> == 0 && s-><a class="code" href="a00026.html#aedbb714bf5d5ef9a28b5ff048321ed99" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a> == 0) <a name="l00081"></a>00081 <a class="code" href="a00047.html#af0f99e8f322ea4eef2d9deaa505239a6">TAILQ_INSERT_HEAD</a>(&<a class="code" href="a00073.html#a9fecba0738529e3d9ff0d4fa7c31ffa9">outputs</a>, s, <a class="code" href="a00073.html#a9fecba0738529e3d9ff0d4fa7c31ffa9">outputs</a>); <a name="l00082"></a>00082 <span class="keywordflow">else</span> <a class="code" href="a00047.html#a512bee16b46f601078c96c776d2648c3">TAILQ_INSERT_TAIL</a>(&<a class="code" href="a00073.html#a9fecba0738529e3d9ff0d4fa7c31ffa9">outputs</a>, s, <a class="code" href="a00073.html#a9fecba0738529e3d9ff0d4fa7c31ffa9">outputs</a>); <a name="l00083"></a>00083 <a class="code" href="a00071.html#a59ff745efdee354cf2bc3dd370fec282">num_screens</a>++; <a name="l00084"></a>00084 } <a name="l00085"></a>00085 <a name="l00086"></a>00086 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"found Xinerama screen: %d x %d at %d x %d\n"</span>, <a name="l00087"></a>00087 screen_info[screen].width, screen_info[screen].height, <a name="l00088"></a>00088 screen_info[screen].x_org, screen_info[screen].y_org); <a name="l00089"></a>00089 } <a name="l00090"></a>00090 <a name="l00091"></a>00091 free(reply); <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="keywordflow">if</span> (<a class="code" href="a00071.html#a59ff745efdee354cf2bc3dd370fec282">num_screens</a> == 0) { <a name="l00094"></a>00094 <a class="code" href="a00044.html#a6828c68e0feb4b7fdfe0fc3ba9f3038b">ELOG</a>(<span class="stringliteral">"No screens found. Please fix your setup. i3 will exit now.\n"</span>); <a name="l00095"></a>00095 exit(0); <a name="l00096"></a>00096 } <a name="l00097"></a>00097 } <a name="l00098"></a>00098 <a name="l00099"></a>00099 <span class="comment">/*</span> <a name="l00100"></a>00100 <span class="comment"> * We have just established a connection to the X server and need the initial Xinerama</span> <a name="l00101"></a>00101 <span class="comment"> * information to setup workspaces for each screen.</span> <a name="l00102"></a>00102 <span class="comment"> *</span> <a name="l00103"></a>00103 <span class="comment"> */</span> <a name="l00104"></a><a class="code" href="a00055.html#a93044db4172ab2447725a2bee3065931">00104</a> <span class="keywordtype">void</span> <a class="code" href="a00080.html#a93044db4172ab2447725a2bee3065931" title="We have just established a connection to the X server and need the initial Xinerama...">initialize_xinerama</a>(xcb_connection_t *conn) { <a name="l00105"></a>00105 <span class="keywordflow">if</span> (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) { <a name="l00106"></a>00106 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Xinerama extension not found, disabling.\n"</span>); <a name="l00107"></a>00107 <a class="code" href="a00073.html#a0d7c5d1d6273f607dc9285621e988e08" title="Disables RandR support by creating exactly one output with the size of the X11 screen...">disable_randr</a>(conn); <a name="l00108"></a>00108 } <span class="keywordflow">else</span> { <a name="l00109"></a>00109 xcb_xinerama_is_active_reply_t *reply; <a name="l00110"></a>00110 reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL); <a name="l00111"></a>00111 <a name="l00112"></a>00112 <span class="keywordflow">if</span> (reply == NULL || !reply->state) { <a name="l00113"></a>00113 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Xinerama is not active (in your X-Server), disabling.\n"</span>); <a name="l00114"></a>00114 <a class="code" href="a00073.html#a0d7c5d1d6273f607dc9285621e988e08" title="Disables RandR support by creating exactly one output with the size of the X11 screen...">disable_randr</a>(conn); <a name="l00115"></a>00115 } <span class="keywordflow">else</span> <a name="l00116"></a>00116 <a class="code" href="a00080.html#a6c10a3a62f737a084108860feb421d94">query_screens</a>(conn); <a name="l00117"></a>00117 <a name="l00118"></a>00118 <a class="code" href="a00052.html#ae88e84de75be0b138a19509d288b4cf4">FREE</a>(reply); <a name="l00119"></a>00119 } <a name="l00120"></a>00120 <a name="l00121"></a>00121 <a class="code" href="a00026.html" title="An Output is a physical output on your graphics driver.">Output</a> *output; <a name="l00122"></a>00122 <a class="code" href="a00025.html" title="The concept of Workspaces is known from various other window managers.">Workspace</a> *ws; <a name="l00123"></a>00123 <span class="comment">/* Just go through each active output and associate one workspace */</span> <a name="l00124"></a>00124 <a class="code" href="a00047.html#a16e5fc168e7f3494d4b1df54447d871e">TAILQ_FOREACH</a>(output, &<a class="code" href="a00073.html#a9fecba0738529e3d9ff0d4fa7c31ffa9">outputs</a>, <a class="code" href="a00073.html#a9fecba0738529e3d9ff0d4fa7c31ffa9">outputs</a>) { <a name="l00125"></a>00125 ws = <a class="code" href="a00078.html#a3fae69bcec850a9a117b9f0cee6a19c0" title="Gets the first unused workspace for the given screen, taking into account the preferred_screen...">get_first_workspace_for_output</a>(output); <a name="l00126"></a>00126 <a class="code" href="a00073.html#a3b4d451b80a25c4d2df53a45f85ee637" title="Initializes the specified output, assigning the specified workspace to it.">initialize_output</a>(conn, output, ws); <a name="l00127"></a>00127 } <a name="l00128"></a>00128 } </pre></div></div> <hr class="footer"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2-20100208 </small></address> </body> </html>