<!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/ewmh.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/ewmh.c</h1><a href="a00065.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"> * ewmh.c: Functions to get/set certain EWMH properties easily.</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 <stdint.h></span> <a name="l00014"></a>00014 <span class="preprocessor">#include <string.h></span> <a name="l00015"></a>00015 <span class="preprocessor">#include <stdlib.h></span> <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="a00036.html">data.h</a>"</span> <a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="a00051.html">table.h</a>"</span> <a name="l00019"></a>00019 <span class="preprocessor">#include "<a class="code" href="a00041.html">i3.h</a>"</span> <a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="a00054.html">xcb.h</a>"</span> <a name="l00021"></a>00021 <span class="preprocessor">#include "<a class="code" href="a00052.html">util.h</a>"</span> <a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="a00044.html">log.h</a>"</span> <a name="l00023"></a>00023 <a name="l00024"></a>00024 <span class="comment">/*</span> <a name="l00025"></a>00025 <span class="comment"> * Updates _NET_CURRENT_DESKTOP with the current desktop number.</span> <a name="l00026"></a>00026 <span class="comment"> *</span> <a name="l00027"></a>00027 <span class="comment"> * EWMH: The index of the current desktop. This is always an integer between 0</span> <a name="l00028"></a>00028 <span class="comment"> * and _NET_NUMBER_OF_DESKTOPS - 1.</span> <a name="l00029"></a>00029 <span class="comment"> *</span> <a name="l00030"></a>00030 <span class="comment"> */</span> <a name="l00031"></a><a class="code" href="a00038.html#ae40835a49409f87f53ad4f7449b19b53">00031</a> <span class="keywordtype">void</span> <a class="code" href="a00065.html#ae40835a49409f87f53ad4f7449b19b53" title="Updates _NET_CURRENT_DESKTOP with the current desktop number.">ewmh_update_current_desktop</a>() { <a name="l00032"></a>00032 uint32_t current_desktop = <a class="code" href="a00076.html#a6dc99dff7063221c1096561951c0386b">c_ws</a>-><a class="code" href="a00025.html#a7dfb9b375b2740db75bb82eb0b2be41d" title="Number of this workspace, starting from 0.">num</a>; <a name="l00033"></a>00033 xcb_change_property(<a class="code" href="a00071.html#ada13c42121d64521629e06e7a5e1db16">global_conn</a>, XCB_PROP_MODE_REPLACE, <a class="code" href="a00071.html#a768f07da9e11ab88732a5c550ff49257">root</a>, <a name="l00034"></a>00034 <a class="code" href="a00071.html#a327a6e1e08087496e9cb60b9e6f2a499">atoms</a>[<a class="code" href="a00054.html#a726ca809ffd3d67ab4b8476646f26635a7b3651a6efcb0970efc89dc301c91e5e">_NET_CURRENT_DESKTOP</a>], CARDINAL, 32, 1, <a name="l00035"></a>00035 &current_desktop); <a name="l00036"></a>00036 } <a name="l00037"></a>00037 <a name="l00038"></a>00038 <span class="comment">/*</span> <a name="l00039"></a>00039 <span class="comment"> * Updates _NET_ACTIVE_WINDOW with the currently focused window.</span> <a name="l00040"></a>00040 <span class="comment"> *</span> <a name="l00041"></a>00041 <span class="comment"> * EWMH: The window ID of the currently active window or None if no window has</span> <a name="l00042"></a>00042 <span class="comment"> * the focus.</span> <a name="l00043"></a>00043 <span class="comment"> *</span> <a name="l00044"></a>00044 <span class="comment"> */</span> <a name="l00045"></a><a class="code" href="a00038.html#a07da16d476a61d9ef63f31de1dc84700">00045</a> <span class="keywordtype">void</span> <a class="code" href="a00065.html#a07da16d476a61d9ef63f31de1dc84700" title="Updates _NET_ACTIVE_WINDOW with the currently focused window.">ewmh_update_active_window</a>(xcb_window_t window) { <a name="l00046"></a>00046 xcb_change_property(<a class="code" href="a00071.html#ada13c42121d64521629e06e7a5e1db16">global_conn</a>, XCB_PROP_MODE_REPLACE, <a class="code" href="a00071.html#a768f07da9e11ab88732a5c550ff49257">root</a>, <a name="l00047"></a>00047 <a class="code" href="a00071.html#a327a6e1e08087496e9cb60b9e6f2a499">atoms</a>[<a class="code" href="a00054.html#a726ca809ffd3d67ab4b8476646f26635ac34e05dfa966932f57aad3f572ed01f2">_NET_ACTIVE_WINDOW</a>], WINDOW, 32, 1, &window); <a name="l00048"></a>00048 } <a name="l00049"></a>00049 <a name="l00050"></a>00050 <span class="comment">/*</span> <a name="l00051"></a>00051 <span class="comment"> * Updates the workarea for each desktop.</span> <a name="l00052"></a>00052 <span class="comment"> *</span> <a name="l00053"></a>00053 <span class="comment"> * EWMH: Contains a geometry for each desktop. These geometries specify an area</span> <a name="l00054"></a>00054 <span class="comment"> * that is completely contained within the viewport. Work area SHOULD be used by</span> <a name="l00055"></a>00055 <span class="comment"> * desktop applications to place desktop icons appropriately.</span> <a name="l00056"></a>00056 <span class="comment"> *</span> <a name="l00057"></a>00057 <span class="comment"> */</span> <a name="l00058"></a><a class="code" href="a00038.html#aefdaf6a17c2aa3979c49e3ff74cfee56">00058</a> <span class="keywordtype">void</span> <a class="code" href="a00065.html#aefdaf6a17c2aa3979c49e3ff74cfee56" title="Updates the workarea for each desktop.">ewmh_update_workarea</a>() { <a name="l00059"></a>00059 <a class="code" href="a00025.html" title="The concept of Workspaces is known from various other window managers.">Workspace</a> *ws; <a name="l00060"></a>00060 <span class="keywordtype">int</span> <a class="code" href="a00076.html#ad1e4ea5850c1dfc18a73382610be5650">num_workspaces</a> = 0, count = 0; <a name="l00061"></a>00061 <a class="code" href="a00020.html" title="Stores a rectangle, for example the size of a window, the child window etc.">Rect</a> last_rect = {0, 0, 0, 0}; <a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="comment">/* Get the number of workspaces */</span> <a name="l00064"></a>00064 <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="l00065"></a>00065 <span class="comment">/* Check if we need to initialize last_rect. The case that the</span> <a name="l00066"></a>00066 <span class="comment"> * first workspace is all-zero may happen when the user</span> <a name="l00067"></a>00067 <span class="comment"> * assigned workspace 2 for his first screen, for example. Thus</span> <a name="l00068"></a>00068 <span class="comment"> * we need an initialized last_rect in the very first run of</span> <a name="l00069"></a>00069 <span class="comment"> * the following loop. */</span> <a name="l00070"></a>00070 <span class="keywordflow">if</span> (last_rect.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a> == 0 && last_rect.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a> == 0 && <a name="l00071"></a>00071 ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a> != 0 && ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a> != 0) { <a name="l00072"></a>00072 memcpy(&last_rect, &(ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">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="l00073"></a>00073 } <a name="l00074"></a>00074 num_workspaces++; <a name="l00075"></a>00075 } <a name="l00076"></a>00076 <a name="l00077"></a>00077 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"Got %d workspaces\n"</span>, num_workspaces); <a name="l00078"></a>00078 uint8_t *workarea = <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="a00020.html" title="Stores a rectangle, for example the size of a window, the child window etc.">Rect</a>) * num_workspaces); <a name="l00079"></a>00079 <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="l00080"></a>00080 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"storing %d: %dx%d with %d x %d\n"</span>, count, ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a>, <a name="l00081"></a>00081 ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a>, ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a>, ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a>); <a name="l00082"></a>00082 <span class="comment">/* If a workspace is not yet initialized and thus its</span> <a name="l00083"></a>00083 <span class="comment"> * dimensions are zero, we will instead put the dimensions</span> <a name="l00084"></a>00084 <span class="comment"> * of the last workspace in the list. For example firefox</span> <a name="l00085"></a>00085 <span class="comment"> * intersects all workspaces and does not cope so well with</span> <a name="l00086"></a>00086 <span class="comment"> * an all-zero workspace. */</span> <a name="l00087"></a>00087 <span class="keywordflow">if</span> (ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a> == 0 || ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">rect</a>.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a> == 0) { <a name="l00088"></a>00088 <a class="code" href="a00044.html#a287e239c800086178591f5e53f5bb82c">DLOG</a>(<span class="stringliteral">"re-using last_rect (%dx%d, %d, %d)\n"</span>, <a name="l00089"></a>00089 last_rect.<a class="code" href="a00020.html#a6f5ab43ec9da45a9c3ddbc45d9aa3bbc">x</a>, last_rect.<a class="code" href="a00020.html#ac77eddc4cc31fe7881da4a23cdca0ea5">y</a>, last_rect.<a class="code" href="a00020.html#adb31dc42e48628c3e513c60296779ef8">width</a>, <a name="l00090"></a>00090 last_rect.<a class="code" href="a00020.html#a0a074c07d144c9647e3eb60ef54f88c3">height</a>); <a name="l00091"></a>00091 memcpy(workarea + (<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>) * count++), &last_rect, <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="l00092"></a>00092 <span class="keywordflow">continue</span>; <a name="l00093"></a>00093 } <a name="l00094"></a>00094 memcpy(workarea + (<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>) * count++), &(ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">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="l00095"></a>00095 memcpy(&last_rect, &(ws-><a class="code" href="a00025.html#ac11bedb880b568b9c540fc9a376607ad" title="x, y, width, height">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="l00096"></a>00096 } <a name="l00097"></a>00097 xcb_change_property(<a class="code" href="a00071.html#ada13c42121d64521629e06e7a5e1db16">global_conn</a>, XCB_PROP_MODE_REPLACE, <a class="code" href="a00071.html#a768f07da9e11ab88732a5c550ff49257">root</a>, <a name="l00098"></a>00098 <a class="code" href="a00071.html#a327a6e1e08087496e9cb60b9e6f2a499">atoms</a>[<a class="code" href="a00054.html#a726ca809ffd3d67ab4b8476646f26635a5258a6a20735e2ae242453ddaf60d157">_NET_WORKAREA</a>], CARDINAL, 32, <a name="l00099"></a>00099 num_workspaces * (<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>) / <span class="keyword">sizeof</span>(uint32_t)), <a name="l00100"></a>00100 workarea); <a name="l00101"></a>00101 free(workarea); <a name="l00102"></a>00102 xcb_flush(<a class="code" href="a00071.html#ada13c42121d64521629e06e7a5e1db16">global_conn</a>); <a name="l00103"></a>00103 } </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>