1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.5.2" />
<title>Hacking i3: How To</title>
<style type="text/css">
/* Debug borders */
p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
/*
border: 1px solid red;
*/
}
body {
margin: 1em 5% 1em 5%;
}
a {
color: blue;
text-decoration: underline;
}
a:visited {
color: fuchsia;
}
em {
font-style: italic;
color: navy;
}
strong {
font-weight: bold;
color: #083194;
}
tt {
color: navy;
}
h1, h2, h3, h4, h5, h6 {
color: #527bbd;
font-family: sans-serif;
margin-top: 1.2em;
margin-bottom: 0.5em;
line-height: 1.3;
}
h1, h2, h3 {
border-bottom: 2px solid silver;
}
h2 {
padding-top: 0.5em;
}
h3 {
float: left;
}
h3 + * {
clear: left;
}
div.sectionbody {
font-family: serif;
margin-left: 0;
}
hr {
border: 1px solid silver;
}
p {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
ul, ol, li > p {
margin-top: 0;
}
pre {
padding: 0;
margin: 0;
}
span#author {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
font-size: 1.1em;
}
span#email {
}
span#revnumber, span#revdate, span#revremark {
font-family: sans-serif;
}
div#footer {
font-family: sans-serif;
font-size: small;
border-top: 2px solid silver;
padding-top: 0.5em;
margin-top: 4.0em;
}
div#footer-text {
float: left;
padding-bottom: 0.5em;
}
div#footer-badges {
float: right;
padding-bottom: 0.5em;
}
div#preamble {
margin-top: 1.5em;
margin-bottom: 1.5em;
}
div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
margin-top: 1.0em;
margin-bottom: 1.5em;
}
div.admonitionblock {
margin-top: 2.0em;
margin-bottom: 2.0em;
margin-right: 10%;
color: #606060;
}
div.content { /* Block element content. */
padding: 0;
}
/* Block element titles. */
div.title, caption.title {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
text-align: left;
margin-top: 1.0em;
margin-bottom: 0.5em;
}
div.title + * {
margin-top: 0;
}
td div.title:first-child {
margin-top: 0.0em;
}
div.content div.title:first-child {
margin-top: 0.0em;
}
div.content + div.title {
margin-top: 0.0em;
}
div.sidebarblock > div.content {
background: #ffffee;
border: 1px solid silver;
padding: 0.5em;
}
div.listingblock > div.content {
border: 1px solid silver;
background: #f4f4f4;
padding: 0.5em;
}
div.quoteblock, div.verseblock {
padding-left: 1.0em;
margin-left: 1.0em;
margin-right: 10%;
border-left: 5px solid #dddddd;
color: #777777;
}
div.quoteblock > div.attribution {
padding-top: 0.5em;
text-align: right;
}
div.verseblock > div.content {
white-space: pre;
}
div.verseblock > div.attribution {
padding-top: 0.75em;
text-align: left;
}
/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
div.verseblock + div.attribution {
text-align: left;
}
div.admonitionblock .icon {
vertical-align: top;
font-size: 1.1em;
font-weight: bold;
text-decoration: underline;
color: #527bbd;
padding-right: 0.5em;
}
div.admonitionblock td.content {
padding-left: 0.5em;
border-left: 3px solid #dddddd;
}
div.exampleblock > div.content {
border-left: 3px solid #dddddd;
padding-left: 0.5em;
}
div.imageblock div.content { padding-left: 0; }
span.image img { border-style: none; }
a.image:visited { color: white; }
dl {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
dt {
margin-top: 0.5em;
margin-bottom: 0;
font-style: normal;
color: navy;
}
dd > *:first-child {
margin-top: 0.1em;
}
ul, ol {
list-style-position: outside;
}
ol.arabic {
list-style-type: decimal;
}
ol.loweralpha {
list-style-type: lower-alpha;
}
ol.upperalpha {
list-style-type: upper-alpha;
}
ol.lowerroman {
list-style-type: lower-roman;
}
ol.upperroman {
list-style-type: upper-roman;
}
div.compact ul, div.compact ol,
div.compact p, div.compact p,
div.compact div, div.compact div {
margin-top: 0.1em;
margin-bottom: 0.1em;
}
div.tableblock > table {
border: 3px solid #527bbd;
}
thead, p.table.header {
font-family: sans-serif;
font-weight: bold;
}
tfoot {
font-weight: bold;
}
td > div.verse {
white-space: pre;
}
p.table {
margin-top: 0;
}
/* Because the table frame attribute is overriden by CSS in most browsers. */
div.tableblock > table[frame="void"] {
border-style: none;
}
div.tableblock > table[frame="hsides"] {
border-left-style: none;
border-right-style: none;
}
div.tableblock > table[frame="vsides"] {
border-top-style: none;
border-bottom-style: none;
}
div.hdlist {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
div.hdlist tr {
padding-bottom: 15px;
}
dt.hdlist1.strong, td.hdlist1.strong {
font-weight: bold;
}
td.hdlist1 {
vertical-align: top;
font-style: normal;
padding-right: 0.8em;
color: navy;
}
td.hdlist2 {
vertical-align: top;
}
div.hdlist.compact tr {
margin: 0;
padding-bottom: 0;
}
.comment {
background: yellow;
}
.footnote, .footnoteref {
font-size: 0.8em;
}
span.footnote, span.footnoteref {
vertical-align: super;
}
#footnotes {
margin: 20px 0 20px 0;
padding: 7px 0 0 0;
}
#footnotes div.footnote {
margin: 0 0 5px 0;
}
#footnotes hr {
border: none;
border-top: 1px solid silver;
height: 1px;
text-align: left;
margin-left: 0;
width: 20%;
min-width: 100px;
}
@media print {
div#footer-badges { display: none; }
}
div#toc {
margin-bottom: 2.5em;
}
div#toctitle {
color: #527bbd;
font-family: sans-serif;
font-size: 1.1em;
font-weight: bold;
margin-top: 1.0em;
margin-bottom: 0.1em;
}
div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
margin-top: 0;
margin-bottom: 0;
}
div.toclevel2 {
margin-left: 2em;
font-size: 0.9em;
}
div.toclevel3 {
margin-left: 4em;
font-size: 0.9em;
}
div.toclevel4 {
margin-left: 6em;
font-size: 0.9em;
}
/* Workarounds for IE6's broken and incomplete CSS2. */
div.sidebar-content {
background: #ffffee;
border: 1px solid silver;
padding: 0.5em;
}
div.sidebar-title, div.image-title {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
margin-top: 0.0em;
margin-bottom: 0.5em;
}
div.listingblock div.content {
border: 1px solid silver;
background: #f4f4f4;
padding: 0.5em;
}
div.quoteblock-attribution {
padding-top: 0.5em;
text-align: right;
}
div.verseblock-content {
white-space: pre;
}
div.verseblock-attribution {
padding-top: 0.75em;
text-align: left;
}
div.exampleblock-content {
border-left: 3px solid #dddddd;
padding-left: 0.5em;
}
/* IE6 sets dynamically generated links as visited. */
div#toc a:visited { color: blue; }
</style>
<script type="text/javascript">
/*<+'])');
// Function that scans the DOM tree for header elements (the DOM2
// nodeIterator API would be a better technique but not supported by all
// browsers).
var iterate = function (el) {
for (var i = el.firstChild; i != null; i = i.nextSibling) {
if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
var mo = re.exec(i.tagName);
if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
}
iterate(i);
}
}
}
iterate(el);
return result;
}
var toc = document.getElementById("toc");
var entries = tocEntries(document.getElementById("content"), toclevels);
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
if (entry.element.id == "")
entry.element.id = "_toc_" + i;
var a = document.createElement("a");
a.href = "#" + entry.element.id;
a.appendChild(document.createTextNode(entry.text));
var div = document.createElement("div");
div.appendChild(a);
div.className = "toclevel" + entry.toclevel;
toc.appendChild(div);
}
if (entries.length == 0)
toc.parentNode.removeChild(toc);
},
/////////////////////////////////////////////////////////////////////
// Footnotes generator
/////////////////////////////////////////////////////////////////////
/* Based on footnote generation code from:
* http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
*/
footnotes: function () {
var cont = document.getElementById("content");
var noteholder = document.getElementById("footnotes");
var spans = cont.getElementsByTagName("span");
var refs = {};
var n = 0;
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnote") {
n++;
// Use [\s\S] in place of . so multi-line matches work.
// Because JavaScript has no s (dotall) regex flag.
note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
noteholder.innerHTML +=
"<div class='footnote' id='_footnote_" + n + "'>" +
"<a href='#_footnoteref_" + n + "' title='Return to text'>" +
n + "</a>. " + note + "</div>";
spans[i].innerHTML =
"[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
var id =spans[i].getAttribute("id");
if (id != null) refs["#"+id] = n;
}
}
if (n == 0)
noteholder.parentNode.removeChild(noteholder);
else {
// Process footnoterefs.
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnoteref") {
var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
href = href.match(/#.*/)[0]; // Because IE return full URL.
n = refs[href];
spans[i].innerHTML =
"[<a href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
}
}
}
}
}
/*]]>*/
</script>
</head>
<body>
<div id="header">
<h1>Hacking i3: How To</h1>
<span id="author">Michael Stapelberg</span><br />
<span id="email"><tt><<a href="mailto:michael+i3@stapelberg.de">michael+i3@stapelberg.de</a>></tt></span><br />
<span id="revdate">December 2009</span>
<div id="toc">
<div id="toctitle">Table of Contents</div>
<noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>This document is intended to be the first thing you read before looking and/or
touching i3’s source code. It should contain all important information to help
you understand why things are like they are. If it does not mention something
you find necessary, please do not hesitate to contact me.</p></div>
</div>
</div>
<h2 id="_window_managers">1. Window Managers</h2>
<div class="sectionbody">
<div class="paragraph"><p>A window manager is not necessarily needed to run X, but it is usually used in
combination with X to facilitate some things. The window manager’s job is to
take care of the placement of windows, to provide the user with some mechanisms
to change the position/size of windows and to communicate with clients to a
certain extent (for example handle fullscreen requests of clients such as
MPlayer).</p></div>
<div class="paragraph"><p>There are no different contexts in which X11 clients run, so a window manager
is just another client, like all other X11 applications. However, it handles
some events which normal clients usually don’t handle.</p></div>
<div class="paragraph"><p>In the case of i3, the tasks (and order of them) are the following:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Grab the key bindings (events will be sent upon keypress/keyrelease)
</p>
</li>
<li>
<p>
Iterate through all existing windows (if the window manager is not started as
the first client of X) and manage them (reparent them, create window
decorations, etc.)
</p>
</li>
<li>
<p>
When new windows are created, manage them
</p>
</li>
<li>
<p>
Handle the client’s <tt>_WM_STATE</tt> property, but only the <tt>_WM_STATE_FULLSCREEN</tt>
</p>
</li>
<li>
<p>
Handle the client’s <tt>WM_NAME</tt> property
</p>
</li>
<li>
<p>
Handle the client’s size hints to display them proportionally
</p>
</li>
<li>
<p>
Handle the client’s urgency hint
</p>
</li>
<li>
<p>
Handle enter notifications (focus follows mouse)
</p>
</li>
<li>
<p>
Handle button (as in mouse buttons) presses for focus/raise on click
</p>
</li>
<li>
<p>
Handle expose events to re-draw own windows such as decorations
</p>
</li>
<li>
<p>
React to the user’s commands: Change focus, Move windows, Switch workspaces,
Change the layout mode of a container (default/stacking/tabbed), start a new
application, restart the window manager
</p>
</li>
</ol></div>
<div class="paragraph"><p>In the following chapters, each of these tasks and their implementation details
will be discussed.</p></div>
<h3 id="_tiling_window_managers">1.1. Tiling window managers</h3><div style="clear:left"></div>
<div class="paragraph"><p>Traditionally, there are two approaches to managing windows: The most common
one nowadays is floating, which means the user can freely move/resize the
windows. The other approach is called tiling, which means that your window
manager distributes windows to use as much space as possible while not
overlapping each other.</p></div>
<div class="paragraph"><p>The idea behind tiling is that you should not need to waste your time
moving/resizing windows while you usually want to get some work done. After
all, most users sooner or later tend to lay out their windows in a way which
corresponds to tiling or stacking mode in i3. Therefore, why not let i3 do this
for you? Certainly, it’s faster than you could ever do it.</p></div>
<div class="paragraph"><p>The problem with most tiling window managers is that they are too unflexible.
In my opinion, a window manager is just another tool, and similar to vim which
can edit all kinds of text files (like source code, HTML, …) and is not limited
to a specific file type, a window manager should not limit itself to a certain
layout (like dwm, awesome, …) but provide mechanisms for you to easily create
the layout you need at the moment.</p></div>
<h3 id="_the_layout_table">1.2. The layout table</h3><div style="clear:left"></div>
<div class="paragraph"><p>To accomplish flexible layouts, we decided to simply use a table. The table
grows and shrinks as you need it. Each cell holds a container which then holds
windows (see picture below). You can use different layouts for each container
(default layout and stacking layout).</p></div>
<div class="paragraph"><p>So, when you open a terminal and immediately open another one, they reside in
the same container, in default layout. The layout table has exactly one column,
one row and therefore one cell. When you move one of the terminals to the
right, the table needs to grow. It will be expanded to two columns and one row.
This enables you to have different layouts for each container. The table then
looks like this:</p></div>
<div class="tableblock">
<table rules="all"
width="15%"
frame="border"
cellspacing="0" cellpadding="4">
<col width="50%" />
<col width="50%" />
<tbody>
<tr>
<td align="center" valign="top"><p class="table">T1</p></td>
<td align="center" valign="top"><p class="table">T2</p></td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph"><p>When moving terminal 2 to the bottom, the table will be expanded again.</p></div>
<div class="tableblock">
<table rules="all"
width="15%"
frame="border"
cellspacing="0" cellpadding="4">
<col width="50%" />
<col width="50%" />
<tbody>
<tr>
<td align="center" valign="top"><p class="table">T1</p></td>
<td align="center" valign="top"><p class="table"></p></td>
</tr>
<tr>
<td align="center" valign="top"><p class="table"></p></td>
<td align="center" valign="top"><p class="table">T2</p></td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph"><p>You can really think of the layout table like a traditional HTML table, if
you’ve ever designed one. Especially col- and rowspan work similarly. Below,
you see an example of colspan=2 for the first container (which has T1 as
window).</p></div>
<div class="tableblock">
<table rules="all"
width="15%"
frame="border"
cellspacing="0" cellpadding="4">
<col width="100%" />
<tbody>
<tr>
<td align="center" valign="top"><div><div class="literalblock">
<div class="content">
<pre><tt>T1</tt></pre>
</div></div></div></td>
</tr>
<tr>
<td align="center" valign="top"><div><div class="tableblock">
<table rules="all"
width="100%"
frame="void"
cellspacing="0" cellpadding="4">
<col width="50%" />
<col width="50%" />
<tbody>
<tr>
<td align="center" valign="top"><p class="table">T2</p></td>
<td align="center" valign="top"><p class="table">T3</p></td>
</tr>
</tbody>
</table>
</div></div></td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph"><p>Furthermore, you can freely resize table cells.</p></div>
</div>
<h2 id="_files">2. Files</h2>
<div class="sectionbody">
<div class="dlist"><dl>
<dt class="hdlist1">
include/data.h
</dt>
<dd>
<p>
Contains data definitions used by nearly all files. You really need to read
this first.
</p>
</dd>
<dt class="hdlist1">
include/*.h
</dt>
<dd>
<p>
Contains forward definitions for all public functions, as well as
doxygen-compatible comments (so if you want to get a bit more of the big
picture, either browse all header files or use doxygen if you prefer that).
</p>
</dd>
<dt class="hdlist1">
src/cfgparse.l
</dt>
<dd>
<p>
Contains the lexer for i3’s configuration file, written for <tt>flex(1)</tt>.
</p>
</dd>
<dt class="hdlist1">
src/cfgparse.y
</dt>
<dd>
<p>
Contains the parser for i3’s configuration file, written for <tt>bison(1)</tt>.
</p>
</dd>
<dt class="hdlist1">
src/click.c
</dt>
<dd>
<p>
Contains all functions which handle mouse button clicks (right mouse button
clicks initiate resizing and thus are relatively complex).
</p>
</dd>
<dt class="hdlist1">
src/client.c
</dt>
<dd>
<p>
Contains all functions which are specific to a certain client (make it
fullscreen, see if its class/name matches a pattern, kill it, …).
</p>
</dd>
<dt class="hdlist1">
src/commands.c
</dt>
<dd>
<p>
Parsing commands and actually executing them (focusing, moving, …).
</p>
</dd>
<dt class="hdlist1">
src/config.c
</dt>
<dd>
<p>
Parses the configuration file.
</p>
</dd>
<dt class="hdlist1">
src/debug.c
</dt>
<dd>
<p>
Contains debugging functions to print unhandled X events.
</p>
</dd>
<dt class="hdlist1">
src/floating.c
</dt>
<dd>
<p>
Contains functions for floating mode (mostly resizing/dragging).
</p>
</dd>
<dt class="hdlist1">
src/handlers.c
</dt>
<dd>
<p>
Contains all handlers for all kinds of X events (new window title, new hints,
unmapping, key presses, button presses, …).
</p>
</dd>
<dt class="hdlist1">
src/ipc.c
</dt>
<dd>
<p>
Contains code for the IPC interface.
</p>
</dd>
<dt class="hdlist1">
src/layout.c
</dt>
<dd>
<p>
Renders your layout (screens, workspaces, containers).
</p>
</dd>
<dt class="hdlist1">
src/mainx.c
</dt>
<dd>
<p>
Initializes the window manager.
</p>
</dd>
<dt class="hdlist1">
src/manage.c
</dt>
<dd>
<p>
Looks at existing or new windows and decides whether to manage them. If so, it
reparents the window and inserts it into our data structures.
</p>
</dd>
<dt class="hdlist1">
src/resize.c
</dt>
<dd>
<p>
Contains the functions to resize columns/rows in the table.
</p>
</dd>
<dt class="hdlist1">
src/table.c
</dt>
<dd>
<p>
Manages the most important internal data structure, the design table.
</p>
</dd>
<dt class="hdlist1">
src/util.c
</dt>
<dd>
<p>
Contains useful functions which are not really dependant on anything.
</p>
</dd>
<dt class="hdlist1">
src/workspace.c
</dt>
<dd>
<p>
Contains all functions related to workspaces (displaying, hiding, renaming…)
</p>
</dd>
<dt class="hdlist1">
src/xcb.c
</dt>
<dd>
<p>
Contains wrappers to use xcb more easily.
</p>
</dd>
<dt class="hdlist1">
src/xinerama.c
</dt>
<dd>
<p>
(Re-)initializes the available screens and converts them to virtual screens
(see below).
</p>
</dd>
</dl></div>
</div>
<h2 id="_data_structures">3. Data structures</h2>
<div class="sectionbody">
<div class="paragraph"><p>See include/data.h for documented data structures. The most important ones are
explained right here.</p></div>
<div class="paragraph"><p><span class="image">
<img src="bigpicture.png" alt="The Big Picture" />
</span></p></div>
<div class="paragraph"><p>So, the hierarchy is:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
<strong>Virtual screens</strong> (Screen 0 in this example)
</p>
</li>
<li>
<p>
<strong>Workspaces</strong> (Workspace 1 in this example)
</p>
</li>
<li>
<p>
<strong>Table</strong> (There can only be one table per Workspace)
</p>
</li>
<li>
<p>
<strong>Container</strong> (left and right in this example)
</p>
</li>
<li>
<p>
<strong>Client</strong> (The two clients in the left container)
</p>
</li>
</ol></div>
<h3 id="_virtual_screens">3.1. Virtual screens</h3><div style="clear:left"></div>
<div class="paragraph"><p>A virtual screen (type <tt>i3Screen</tt>) is generated from the connected screens
obtained through Xinerama. The difference to the raw Xinerama monitors as seen
when using <tt>xrandr(1)</tt> is that it falls back to the lowest common resolution of
the logical screens.</p></div>
<div class="paragraph"><p>For example, if your notebook has 1280x800 and you connect a video projector
with 1024x768, set up in clone mode (<tt>xrandr --output VGA --mode 1024x768
--same-as LVDS</tt>), i3 will have one virtual screen.</p></div>
<div class="paragraph"><p>However, if you configure it using <tt>xrandr --output VGA --mode 1024x768
--right-of LVDS</tt>, i3 will generate two virtual screens. For each virtual
screen, a new workspace will be assigned. New workspaces are created on the
screen you are currently on.</p></div>
<h3 id="_workspace">3.2. Workspace</h3><div style="clear:left"></div>
<div class="paragraph"><p>A workspace is identified by its number. Basically, you could think of
workspaces as different desks in your office, if you like the desktop
methaphor. They just contain different sets of windows and are completely
separate of each other. Other window managers also call this “Virtual
desktops”.</p></div>
<h3 id="_the_layout_table_2">3.3. The layout table</h3><div style="clear:left"></div>
<div class="paragraph"><p>Each workspace has a table, which is just a two-dimensional dynamic array
containing Containers (see below). This table grows and shrinks as you need it
(by moving windows to the right you can create a new column in the table, by
moving them to the bottom you create a new row).</p></div>
<h3 id="_container">3.4. Container</h3><div style="clear:left"></div>
<div class="paragraph"><p>A container is the content of a table’s cell. It holds an arbitrary amount of
windows and has a specific layout (default layout, stack layout or tabbed
layout). Containers can consume multiple table cells by modifying their
colspan/rowspan attribute.</p></div>
<h3 id="_client">3.5. Client</h3><div style="clear:left"></div>
<div class="paragraph"><p>A client is x11-speak for a window.</p></div>
</div>
<h2 id="_list_queue_macros">4. List/queue macros</h2>
<div class="sectionbody">
<div class="paragraph"><p>i3 makes heavy use of the list macros defined in BSD operating systems. To
ensure that the operating system on which i3 is compiled has all the expected
features, i3 comes with <tt>include/queue.h</tt>. On BSD systems, you can use man
<tt>queue(3)</tt>. On Linux, you have to use google (or read the source).</p></div>
<div class="paragraph"><p>The lists used are <tt>SLIST</tt> (single linked lists), <tt>CIRCLEQ</tt> (circular
queues) and TAILQ (tail queues). Usually, only forward traversal is necessary,
so an <tt>SLIST</tt> works fine. If inserting elements at arbitrary positions or at
the end of a list is necessary, a <tt>TAILQ</tt> is used instead. However, for the
windows inside a container, a <tt>CIRCLEQ</tt> is necessary to go from the currently
selected window to the window above/below.</p></div>
</div>
<h2 id="_naming_conventions">5. Naming conventions</h2>
<div class="sectionbody">
<div class="paragraph"><p>There is a row of standard variables used in many events. The following names
should be chosen for those:</p></div>
<div class="ulist"><ul>
<li>
<p>
“conn” is the xcb_connection_t
</p>
</li>
<li>
<p>
“event” is the event of the particular type
</p>
</li>
<li>
<p>
“container” names a container
</p>
</li>
<li>
<p>
“client” names a client, for example when using a <tt>CIRCLEQ_FOREACH</tt>
</p>
</li>
</ul></div>
</div>
<h2 id="_startup_src_mainx_c_main">6. Startup (src/mainx.c, main())</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
Establish the xcb connection
</p>
</li>
<li>
<p>
Check for XKB extension on the separate X connection
</p>
</li>
<li>
<p>
Check for Xinerama screens
</p>
</li>
<li>
<p>
Grab the keycodes for which bindings exist
</p>
</li>
<li>
<p>
Manage all existing windows
</p>
</li>
<li>
<p>
Enter the event loop
</p>
</li>
</ul></div>
</div>
<h2 id="_keybindings">7. Keybindings</h2>
<div class="sectionbody">
<h3 id="_grabbing_the_bindings">7.1. Grabbing the bindings</h3><div style="clear:left"></div>
<div class="paragraph"><p>Grabbing the bindings is quite straight-forward. You pass X your combination of
modifiers and the keycode you want to grab and whether you want to grab them
actively or passively. Most bindings (everything except for bindings using
Mode_switch) are grabbed passively, that is, just the window manager gets the
event and cannot replay it.</p></div>
<div class="paragraph"><p>We need to grab bindings that use Mode_switch actively because of a bug in X.
When the window manager receives the keypress/keyrelease event for an actively
grabbed keycode, it has to decide what to do with this event: It can either
replay it so that other applications get it or it can prevent other
applications from receiving it.</p></div>
<div class="paragraph"><p>So, why do we need to grab keycodes actively? Because X does not set the
state-property of keypress/keyrelease events properly. The Mode_switch bit is
not set and we need to get it using XkbGetState. This means we cannot pass X
our combination of modifiers containing Mode_switch when grabbing the key and
therefore need to grab the keycode itself without any modifiers. This means,
if you bind Mode_switch + keycode 38 ("a"), i3 will grab keycode 38 ("a") and
check on each press of "a" if the Mode_switch bit is set using XKB. If yes, it
will handle the event, if not, it will replay the event.</p></div>
<h3 id="_handling_a_keypress">7.2. Handling a keypress</h3><div style="clear:left"></div>
<div class="paragraph"><p>As mentioned in "Grabbing the bindings", upon a keypress event, i3 first gets
the correct state.</p></div>
<div class="paragraph"><p>Then, it looks through all bindings and gets the one which matches the received
event.</p></div>
<div class="paragraph"><p>The bound command is parsed directly in command mode.</p></div>
</div>
<h2 id="_manage_windows_src_mainx_c_manage_window_and_reparent_window">8. Manage windows (src/mainx.c, manage_window() and reparent_window())</h2>
<div class="sectionbody">
<div class="paragraph"><p><tt>manage_window()</tt> does some checks to decide whether the window should be
managed at all:</p></div>
<div class="ulist"><ul>
<li>
<p>
Windows have to be mapped, that is, visible on screen
</p>
</li>
<li>
<p>
The override_redirect must not be set. Windows with override_redirect shall
not be managed by a window manager
</p>
</li>
</ul></div>
<div class="paragraph"><p>Afterwards, i3 gets the intial geometry and reparents the window (see
<tt>reparent_window()</tt>) if it wasn’t already managed.</p></div>
<div class="paragraph"><p>Reparenting means that for each window which is reparented, a new window,
slightly larger than the original one, is created. The original window is then
reparented to the bigger one (called "frame").</p></div>
<div class="paragraph"><p>After reparenting, the window type (<tt>_NET_WM_WINDOW_TYPE</tt>) is checked to see
whether this window is a dock (<tt>_NET_WM_WINDOW_TYPE_DOCK</tt>), like dzen2 for
example. Docks are handled differently, they don’t have decorations and are not
assigned to a specific container. Instead, they are positioned at the bottom
of the screen. To get the height which needsd to be reserved for the window,
the <tt>_NET_WM_STRUT_PARTIAL</tt> property is used.</p></div>
<div class="paragraph"><p>Furthermore, the list of assignments (to other workspaces, which may be on
other screens) is checked. If the window matches one of the user’s criteria,
it may either be put in floating mode or moved to a different workspace. If the
target workspace is not visible, the window will not be mapped.</p></div>
</div>
<h2 id="_what_happens_when_an_application_is_started">9. What happens when an application is started?</h2>
<div class="sectionbody">
<div class="paragraph"><p>i3 does not care for applications. All it notices is when new windows are
mapped (see <tt>src/handlers.c</tt>, <tt>handle_map_request()</tt>). The window is then
reparented (see section "Manage windows").</p></div>
<div class="paragraph"><p>After reparenting the window, <tt>render_layout()</tt> is called which renders the
internal layout table. The new window has been placed in the currently focused
container and therefore the new window and the old windows (if any) need to be
moved/resized so that the currently active layout (default/stacking/tabbed mode)
is rendered correctly. To move/resize windows, a window is “configured” in
X11-speak.</p></div>
<div class="paragraph"><p>Some applications, such as MPlayer obviously assume the window manager is
stupid and try to configure their windows by themselves. This generates an
event called configurerequest. i3 handles these events and tells the window the
size it had before the configurerequest (with the exception of not yet mapped
windows, which get configured like they want to, and floating windows, which
can reconfigure themselves).</p></div>
</div>
<h2 id="_net_wm_state">10. _NET_WM_STATE</h2>
<div class="sectionbody">
<div class="paragraph"><p>Only the _NET_WM_STATE_FULLSCREEN atom is handled. It calls
“toggle_fullscreen()” for the specific client which just configures the
client to use the whole screen on which it currently is. Also, it is set as
fullscreen_client for the i3Screen.</p></div>
</div>
<h2 id="_wm_name">11. WM_NAME</h2>
<div class="sectionbody">
<div class="paragraph"><p>When the WM_NAME property of a window changes, its decoration (containing the
title) is re-rendered. Note that WM_NAME is in COMPOUND_TEXT encoding which is
totally uncommon and cumbersome. Therefore, the _NET_WM_NAME atom will be used
if present.</p></div>
</div>
<h2 id="_net_wm_name">12. _NET_WM_NAME</h2>
<div class="sectionbody">
<div class="paragraph"><p>Like WM_NAME, this atom contains the title of a window. However, _NET_WM_NAME
is encoded in UTF-8. i3 will recode it to UCS-2 in order to be able to pass it
to X. Using an appropriate font (ISO-10646), you can see most special
characters (every special character contained in your font).</p></div>
</div>
<h2 id="_size_hints">13. Size hints</h2>
<div class="sectionbody">
<div class="paragraph"><p>Size hints specify the minimum/maximum size for a given window as well as its
aspect ratio. This is important for clients like mplayer, who only set the
aspect ratio and resize their window to be as small as possible (but only with
some video outputs, for example in Xv, while when using x11, mplayer does the
necessary centering for itself).</p></div>
<div class="paragraph"><p>So, when an aspect ratio was specified, i3 adjusts the height of the window
until the size maintains the correct aspect ratio. For the code to do this, see
src/layout.c, function resize_client().</p></div>
</div>
<h2 id="_rendering_src_layout_c_render_layout_and_render_container">14. Rendering (src/layout.c, render_layout() and render_container())</h2>
<div class="sectionbody">
<div class="paragraph"><p>There are several entry points to rendering: <tt>render_layout()</tt>,
<tt>render_workspace()</tt> and <tt>render_container()</tt>. The former one calls
<tt>render_workspace()</tt> for every screen, which in turn will call
<tt>render_container()</tt> for every container inside its layout table. Therefore, if
you need to render only a single container, for example because a window was
removed, added or changed its title, you should directly call
render_container().</p></div>
<div class="paragraph"><p>Rendering consists of two steps: In the first one, in <tt>render_workspace()</tt>, each
container gets its position (screen offset + offset in the table) and size
(container’s width times colspan/rowspan). Then, <tt>render_container()</tt> is called,
which takes different approaches, depending on the mode the container is in:</p></div>
<h3 id="_common_parts">14.1. Common parts</h3><div style="clear:left"></div>
<div class="paragraph"><p>On the frame (the window which was created around the client’s window for the
decorations), a black rectangle is drawn as a background for windows like
MPlayer, which do not completely fit into the frame.</p></div>
<h3 id="_default_mode">14.2. Default mode</h3><div style="clear:left"></div>
<div class="paragraph"><p>Each clients gets the container’s width and an equal amount of height.</p></div>
<h3 id="_stack_mode">14.3. Stack mode</h3><div style="clear:left"></div>
<div class="paragraph"><p>In stack mode, a window containing the decorations of all windows inside the
container is placed at the top. The currently focused window is then given the
whole remaining space.</p></div>
<h3 id="_tabbed_mode">14.4. Tabbed mode</h3><div style="clear:left"></div>
<div class="paragraph"><p>Tabbed mode is like stack mode, except that the window decorations are drawn
in one single line at the top of the container.</p></div>
<h3 id="_window_decorations">14.5. Window decorations</h3><div style="clear:left"></div>
<div class="paragraph"><p>The window decorations consist of a rectangle in the appropriate color (depends
on whether this window is the currently focused one, the last focused one in a
not focused container or not focused at all) forming the background.
Afterwards, two lighter lines are drawn and the last step is drawing the
window’s title (see WM_NAME) onto it.</p></div>
<h3 id="_fullscreen_windows">14.6. Fullscreen windows</h3><div style="clear:left"></div>
<div class="paragraph"><p>For fullscreen windows, the <tt>rect</tt> (x, y, width, height) is not changed to
allow the client to easily go back to its previous position. Instead,
fullscreen windows are skipped when rendering.</p></div>
<h3 id="_resizing_containers">14.7. Resizing containers</h3><div style="clear:left"></div>
<div class="paragraph"><p>By clicking and dragging the border of a container, you can resize the whole
column (respectively row) which this container is in. This is necessary to keep
the table layout working and consistent.</p></div>
<div class="paragraph"><p>The resizing works similarly to the resizing of floating windows or movement of
floating windows:</p></div>
<div class="ulist"><ul>
<li>
<p>
A new, invisible window with the size of the root window is created
(<tt>grabwin</tt>)
</p>
</li>
<li>
<p>
Another window, 2px width and as high as your screen (or vice versa for
horizontal resizing) is created. Its background color is the border color and
it is only there to inform the user how big the container will be (it
creates the impression of dragging the border out of the container).
</p>
</li>
<li>
<p>
The <tt>drag_pointer</tt> function of <tt>src/floating.c</tt> is called to grab the pointer
and enter its own event loop which will pass all events (expose events) but
motion notify events. This function then calls the specified callback
(<tt>resize_callback</tt>) which does some boundary checking and moves the helper
window. As soon as the mouse button is released, this loop will be
terminated.
</p>
</li>
<li>
<p>
The new width_factor for each involved column (respectively row) will be
calculated.
</p>
</li>
</ul></div>
</div>
<h2 id="_user_commands_commandmode_src_commands_c">15. User commands / commandmode (src/commands.c)</h2>
<div class="sectionbody">
<div class="paragraph"><p>Like in vim, you can control i3 using commands. They are intended to be a
powerful alternative to lots of shortcuts, because they can be combined. There
are a few special commands, which are the following:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
exec <command>
</dt>
<dd>
<p>
Starts the given command by passing it to <tt>/bin/sh</tt>.
</p>
</dd>
<dt class="hdlist1">
restart
</dt>
<dd>
<p>
Restarts i3 by executing <tt>argv[0]</tt> (the path with which you started i3) without
forking.
</p>
</dd>
<dt class="hdlist1">
w
</dt>
<dd>
<p>
"With". This is used to select a bunch of windows. Currently, only selecting
the whole container in which the window is in, is supported by specifying "w".
</p>
</dd>
<dt class="hdlist1">
f, s, d
</dt>
<dd>
<p>
Toggle fullscreen, stacking, default mode for the current window/container.
</p>
</dd>
</dl></div>
<div class="paragraph"><p>The other commands are to be combined with a direction. The directions are h,
j, k and l, like in vim (h = left, j = down, k = up, l = right). When you just
specify the direction keys, i3 will move the focus in that direction. You can
provide "m" or "s" before the direction to move a window respectively or snap.</p></div>
</div>
<h2 id="_gotchas">16. Gotchas</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
Forgetting to call <tt>xcb_flush(conn);</tt> after sending a request. This usually
leads to code which looks like it works fine but which does not work under
certain conditions.
</p>
</li>
</ul></div>
</div>
<h2 id="_using_git_sending_patches">17. Using git / sending patches</h2>
<div class="sectionbody">
<div class="paragraph"><p>For a short introduction into using git, see
<a href="http://www.spheredev.org/wiki/Git_for_the_lazy">http://www.spheredev.org/wiki/Git_for_the_lazy</a> or, for more documentation, see
<a href="http://git-scm.com/documentation">http://git-scm.com/documentation</a></p></div>
<div class="paragraph"><p>When you want to send a patch because you fixed a bug or implemented a cool
feature (please talk to us before working on features to see whether they are
maybe already implemented, not possible for some some reason, or don’t fit
into the concept), please use git to create a patchfile.</p></div>
<div class="paragraph"><p>First of all, update your working copy to the latest version of the master
branch:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>git pull</tt></pre>
</div></div>
<div class="paragraph"><p>Afterwards, make the necessary changes for your bugfix/feature. Then, review
the changes using <tt>git diff</tt> (you might want to enable colors in the diff using
<tt>git config diff.color auto</tt>). When you are definitely done, use <tt>git commit
-a</tt> to commit all changes you’ve made.</p></div>
<div class="paragraph"><p>Then, use the following command to generate a patchfile which we can directly
apply to the branch, preserving your commit message and name:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>git format-patch origin</tt></pre>
</div></div>
<div class="paragraph"><p>Just send us the generated file via email.</p></div>
</div>
</div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
Last updated 2010-03-30 12:56:34 CEST
</div>
</div>
</body>
</html>
|