Alopex

Changes On Branch master

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch master Excluding Merge-Ins

This is equivalent to a diff from 45f6523171 to 2e35545abe

2014-06-22
22:12
Merge pull request #51 from pfernie/mod_mask_support Support ModX Bind.Mod values besides just Mod4 Leaf check-in: 2e35545abe user: jesse@mccluresk9.com tags: trunk, master
22:08
Merge pull request #50 from pfernie/focus_up Initialize Client *b to NULL check-in: e3c8a65315 user: jesse@mccluresk9.com tags: trunk, master
20:24
Support ModX Bind.Mod values besides just Mod4 Allow user to specify Mod1, Mod2, etc. as Bind.Mod values check-in: 42fdaaf0e5 user: patrick.fernie@gmail.com tags: trunk, master
2013-11-29
03:24
ver 3 coming soon Leaf check-in: 888df91866 user: mcclure_jesse@msn.com tags: trunk, origin/version2
03:15
ver 3 coming soon check-in: 1358d57fac user: mcclure_jesse@msn.com tags: trunk, master
2013-11-22
21:18
added ignore_root_resize check-in: 45f6523171 user: jesse@mccluresk9.com tags: trunk, origin/version2
2013-10-03
17:46
added internationalization to property change notify to handle firefox check-in: 4547f9c17c user: jesse@mccluresk9.com tags: trunk, origin/version2

Deleted COPYING.

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
                    GNU GENERAL PUBLIC LICENSE
                       Version 3, 29 June 2007

 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

                            Preamble

  The GNU General Public License is a free, copyleft license for
software and other kinds of works.

  The licenses for most software and other practical works are designed
to take away your freedom to share and change the works.  By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.  We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors.  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

  To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights.  Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received.  You must make sure that they, too, receive
or can get the source code.  And you must show them these terms so they
know their rights.

  Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.

  For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software.  For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.

  Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so.  This is fundamentally incompatible with the aim of
protecting users' freedom to change the software.  The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable.  Therefore, we
have designed this version of the GPL to prohibit the practice for those
products.  If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.

  Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary.  To prevent this, the GPL assures that
patents cannot be used to render the program non-free.

  The precise terms and conditions for copying, distribution and
modification follow.

                       TERMS AND CONDITIONS

  0. Definitions.

  "This License" refers to version 3 of the GNU General Public License.

  "Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.

  "The Program" refers to any copyrightable work licensed under this
License.  Each licensee is addressed as "you".  "Licensees" and
"recipients" may be individuals or organizations.

  To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy.  The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.

  A "covered work" means either the unmodified Program or a work based
on the Program.

  To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy.  Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.

  To "convey" a work means any kind of propagation that enables other
parties to make or receive copies.  Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.

  An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License.  If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.

  1. Source Code.

  The "source code" for a work means the preferred form of the work
for making modifications to it.  "Object code" means any non-source
form of a work.

  A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.

  The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form.  A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.

  The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities.  However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work.  For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.

  The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.

  The Corresponding Source for a work in source code form is that
same work.

  2. Basic Permissions.

  All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met.  This License explicitly affirms your unlimited
permission to run the unmodified Program.  The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work.  This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.

  You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force.  You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright.  Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.

  Conveying under any other circumstances is permitted solely under
the conditions stated below.  Sublicensing is not allowed; section 10
makes it unnecessary.

  3. Protecting Users' Legal Rights From Anti-Circumvention Law.

  No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.

  When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.

  4. Conveying Verbatim Copies.

  You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.

  You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.

  5. Conveying Modified Source Versions.

  You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:

    a) The work must carry prominent notices stating that you modified
    it, and giving a relevant date.

    b) The work must carry prominent notices stating that it is
    released under this License and any conditions added under section
    7.  This requirement modifies the requirement in section 4 to
    "keep intact all notices".

    c) You must license the entire work, as a whole, under this
    License to anyone who comes into possession of a copy.  This
    License will therefore apply, along with any applicable section 7
    additional terms, to the whole of the work, and all its parts,
    regardless of how they are packaged.  This License gives no
    permission to license the work in any other way, but it does not
    invalidate such permission if you have separately received it.

    d) If the work has interactive user interfaces, each must display
    Appropriate Legal Notices; however, if the Program has interactive
    interfaces that do not display Appropriate Legal Notices, your
    work need not make them do so.

  A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit.  Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.

  6. Conveying Non-Source Forms.

  You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:

    a) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by the
    Corresponding Source fixed on a durable physical medium
    customarily used for software interchange.

    b) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by a
    written offer, valid for at least three years and valid for as
    long as you offer spare parts or customer support for that product
    model, to give anyone who possesses the object code either (1) a
    copy of the Corresponding Source for all the software in the
    product that is covered by this License, on a durable physical
    medium customarily used for software interchange, for a price no
    more than your reasonable cost of physically performing this
    conveying of source, or (2) access to copy the
    Corresponding Source from a network server at no charge.

    c) Convey individual copies of the object code with a copy of the
    written offer to provide the Corresponding Source.  This
    alternative is allowed only occasionally and noncommercially, and
    only if you received the object code with such an offer, in accord
    with subsection 6b.

    d) Convey the object code by offering access from a designated
    place (gratis or for a charge), and offer equivalent access to the
    Corresponding Source in the same way through the same place at no
    further charge.  You need not require recipients to copy the
    Corresponding Source along with the object code.  If the place to
    copy the object code is a network server, the Corresponding Source
    may be on a different server (operated by you or a third party)
    that supports equivalent copying facilities, provided you maintain
    clear directions next to the object code saying where to find the
    Corresponding Source.  Regardless of what server hosts the
    Corresponding Source, you remain obligated to ensure that it is
    available for as long as needed to satisfy these requirements.

    e) Convey the object code using peer-to-peer transmission, provided
    you inform other peers where the object code and Corresponding
    Source of the work are being offered to the general public at no
    charge under subsection 6d.

  A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.

  A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling.  In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage.  For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product.  A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.

  "Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source.  The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.

  If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information.  But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).

  The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed.  Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.

  Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.

  7. Additional Terms.

  "Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law.  If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.

  When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it.  (Additional permissions may be written to require their own
removal in certain cases when you modify the work.)  You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.

  Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:

    a) Disclaiming warranty or limiting liability differently from the
    terms of sections 15 and 16 of this License; or

    b) Requiring preservation of specified reasonable legal notices or
    author attributions in that material or in the Appropriate Legal
    Notices displayed by works containing it; or

    c) Prohibiting misrepresentation of the origin of that material, or
    requiring that modified versions of such material be marked in
    reasonable ways as different from the original version; or

    d) Limiting the use for publicity purposes of names of licensors or
    authors of the material; or

    e) Declining to grant rights under trademark law for use of some
    trade names, trademarks, or service marks; or

    f) Requiring indemnification of licensors and authors of that
    material by anyone who conveys the material (or modified versions of
    it) with contractual assumptions of liability to the recipient, for
    any liability that these contractual assumptions directly impose on
    those licensors and authors.

  All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10.  If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term.  If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.

  If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.

  Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.

  8. Termination.

  You may not propagate or modify a covered work except as expressly
provided under this License.  Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).

  However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.

  Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.

  Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License.  If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.

  9. Acceptance Not Required for Having Copies.

  You are not required to accept this License in order to receive or
run a copy of the Program.  Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance.  However,
nothing other than this License grants you permission to propagate or
modify any covered work.  These actions infringe copyright if you do
not accept this License.  Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.

  10. Automatic Licensing of Downstream Recipients.

  Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License.  You are not responsible
for enforcing compliance by third parties with this License.

  An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations.  If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.

  You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License.  For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.

  11. Patents.

  A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based.  The
work thus licensed is called the contributor's "contributor version".

  A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version.  For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.

  Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.

  In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement).  To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.

  If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients.  "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.

  If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.

  A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License.  You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.

  Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.

  12. No Surrender of Others' Freedom.

  If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all.  For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.

  13. Use with the GNU Affero General Public License.

  Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work.  The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.

  14. Revised Versions of this License.

  The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

  Each version is given a distinguishing version number.  If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation.  If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.

  If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.

  Later license versions may give you additional or different
permissions.  However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.

  15. Disclaimer of Warranty.

  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. Limitation of Liability.

  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.

  17. Interpretation of Sections 15 and 16.

  If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

                     END OF TERMS AND CONDITIONS

            How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

  If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

    <program>  Copyright (C) <year>  <name of author>
    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".

  You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.

  The GNU General Public License does not permit incorporating your program
into proprietary programs.  If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library.  If this is what you want to do, use the GNU Lesser General
Public License instead of this License.  But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Changes to Makefile.

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











PROG	=	alopex
LIBS	=	-lX11 -lXrandr
PREFIX	?=	/usr
MANDIR	?=	/usr/share/man
VER		=	2.0
HEADERS	=	config.h icons.h theme.h
MOLT	?=	WinterCoat

${PROG}: ${PROG}.c ${HEADERS}
	@${CC} -D${MOLT} ${CFLAGS} ${LIBS} -o ${PROG} ${PROG}.c
	@strip ${PROG}

clean:
	@rm -f ${PROG}

tarball: clean
	@rm -f ${PROG}-${VER}.tar.gz
	@tar -czf ${PROG}-${VER}.tar.gz *

install: ${PROG}
	@install -Dm755 ${PROG} ${DESTDIR}${PREFIX}/bin/${PROG}
	@install -Dm666 ${PROG}.1 ${DESTDIR}${MANDIR}/man1/${PROG}.1
	@install -Dm666 ${PROG}.config.5 ${DESTDIR}${MANDIR}/man5/${PROG}.config.5
	@install -Dm666 ${PROG}.icons.5 ${DESTDIR}${MANDIR}/man5/${PROG}.icons.5














|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
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

PROG     =  alopex
VER      =  4.0a
CC       ?= gcc
CFLAGS   += $(shell pkg-config --cflags x11 cairo freetype2 xinerama)
LDLIBS   += $(shell pkg-config --libs x11 cairo freetype2 xinerama)
PREFIX   ?= /usr
MODULES  =  actions alopex atoms config draw tile xlib
HEADERS  =  alopex.h actions.h
MANPAGES =  alopex.1
VPATH    =  src:doc

${PROG}: ${MODULES:%=%.o}

%.o: %.c ${HEADERS}

install: ${PROG}
	@install -Dm755 ${PROG} ${DESTDIR}${PREFIX}/bin/${PROG}
	@mkdir -p ${DESTDIR}${PREFIX}/share/${PROG}
	@install -m644 -t ${DESTDIR}${PREFIX}/share/${PROG}/ share/*
	@install -Dm644 doc/alopex.1 ${DESTDIR}${PREFIX}/share/man/man1/alopex.1

${MANPAGES}: alopex.%: alopex-%.tex
	@latex2man $< doc/$@

man: ${MANPAGES}

clean:
	@rm -f ${PROG}-${VER}.tar.gz
	@rm -f ${MODULES:%=%.o}

distclean: clean
	@rm -f ${PROG}

dist: distclean
	@tar -czf ${PROG}-${VER}.tar.gz *

.PHONY: clean dist distclean man

Changes to PKGBUILD.

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
# Maintainer: Jesse McClure AKA "Trilby" <jmcclure [at] cns [dot] umass [dot] edu>
_gitname="alopex"
pkgname="${_gitname}-git"
pkgver=2.291.1763f16
pkgrel=1
pkgdesc="A Tiny, Tabbed, Tiling Window Manager with Fur"
url="http://trilbywhite.github.io/alopex/"
arch=('any')
license=('GPLv3')
depends=('libx11' 'libxrandr')
makedepends=('git')
source=("${_gitname}::git://github.com/TrilbyWhite/alopex.git")
sha256sums=('SKIP')

pkgver() {
	cd "${_gitname}";
	echo "2.$(git rev-list --count HEAD).$(git describe --always )"
}

prepare() {
	_dir="$HOME/.config/alopex"
	[[ -n "$XDG_CONFIG_HOME" ]] && _dir="$XDG_CONFIG_HOME/alopex"
	if [[ -d "$_dir" ]]; then
		for _file in {config,icons,theme}.h; do
			if [[ -a "${_dir}/${_file}" ]]; then
				cp "${_dir}/${_file}" "${srcdir}/${_gitname}/${_file}"
				msg2 "Using ${_file%.h} from $_dir/$_file"
				msg2 "Check the default $_file for changes"
			fi
		done
	fi
}

build() {
	cd "${_gitname}"
	make
}

package() {
	cd "${_gitname}"
	make PREFIX=/usr DESTDIR="${pkgdir}" install
}



|

|

|
|
|






|
<
<
<
<
<
<
<
<
<
<
<
<
<
<











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
# Maintainer: Jesse McClure AKA "Trilby" <jmcclure [at] cns [dot] umass [dot] edu>
_gitname="alopex"
pkgname="${_gitname}-git"
pkgver=4.420.bbd6ee2
pkgrel=1
pkgdesc="A Tabbed, Tiling Window Manager with Fur"
url="http://trilbywhite.github.io/alopex/"
arch=('x86_64' 'i686')
license=('GPL3')
depends=('libxinerama' 'cairo')
makedepends=('git')
source=("${_gitname}::git://github.com/TrilbyWhite/alopex.git")
sha256sums=('SKIP')

pkgver() {
	cd "${_gitname}";
	echo "4.$(git rev-list --count HEAD).$(git describe --always )"














}

build() {
	cd "${_gitname}"
	make
}

package() {
	cd "${_gitname}"
	make PREFIX=/usr DESTDIR="${pkgdir}" install
}

Changes to README.md.


1
2
3
4
5
6
7
8











Alopex
======
Don't be a lagopus!

[![alopex banner](https://raw.github.com/TrilbyWhite/alopex/gh-pages/res/alopex.jpg)](http://trilbywhite.github.com/alopex)













>




|



>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Alopex
======
Don't be a lagopus!

[![alopex banner](https://raw.github.com/TrilbyWhite/alopex/gh-pages/res/alopex.jpg)See the website here](http://trilbywhite.github.com/alopex)



### 22 March 2014

- There may be issues with the cairo drawing functions used by alopex
  and some nvidia drivers.  Unfortunately I have no way of tracking down
  this issue.  If you have a nvidia card, either 1) use the FOSS
  drivers, 2) use another WM, and/or 3) help pinpoint if and where the
  issue lies between cairo and nvidia and report it to their devs.

- There is a known bug with gtk3 windows not being drawn.  This is next
  on my chopping block and a fix can be expected soon.

Added TODO.





>
>
1
2

reconfigure on monitor changes.

Deleted alopex.1.

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
'\" t
.\"     Title: alopex
.\"    Author: [Sam Stuewe]
.\"      Date: 2013-04-22
.\"    Manual: \ \&
.\"    Source: \ \& 2.0
.\"  Language: English
.\"
.TH "ALOPEX" "1" "2013-04-23" "\ \& 2\&.0" "\ \&"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.nh
.ad l
.\"
.\" <- Main Content ->
.SH "NAME"
Alopex \- A Tabbed Tiling Window Manager
.SH "SYNOPSIS"
.sp
xinit /usr/bin/\fBalopex\fR "/path/to/statusbar-script.sh"
.sp
.SH "DESCRIPTION"
Almost all configuration for \fBalopex\fR is done at compile-time\&. Customizations such as keybinds, statusbar icons, tag appearances and window rules can be achieved through three C header files\&: config\&.h, icons\&.h and theme\&.h\&.
.sp
The default headers will provide simple, sane defaults, but users should expect to customize the setup to their liking\&.
.sp
.SH "WINDOW LAYOUTS"
\fBAlopex\fR offers three window layouts\&: rstack, bstack and monocle\&. Both stack modes divide the screen into two sections, the master region and the stack\&. Monocle keeps the screen unified in one region\&. All layouts render a tab per-client to the right of the tags and the left of the statusbar\&.
.sp
.RS 4
.nf
\fIrstack\fR    \-\-  master on left, stack on right; clients stack vertically
\fIbstack\fR    \-\-  master on top, stack on bottom; clients stack horizontally
\fImonocle\fR   \-\-  master region fills the screen
.fi
.sp
.RE
These three layouts are further supplemented by transient, floating and fullscreen modes\&.
.sp
.SH "THEMES"
Themes for \fBalopex\fR are sets of standard \fI#RRGGBB\fR hex codes assigned to various parts of the interface\&. By default, two themes are provided called "WinterCoat" and "SummerCoat" with several others under construction\&. However, through creating a custom theme\&.h located at \fI$XDG_CONFIG_HOME/alopex/theme\&.h\fR or \fI$HOME/.alopex_theme.h\fR, creating custom themes is very simple\&.
.sp
.SH "STATUSBAR"
A single argument can be passed to \fBalopex\fR to render a statusbar\&. To avoid a CPU race, \fBalopex\fR creates a simple statusbar displaying a clock\&. However, by passing a script or program that can output text (such as conky), far more complex statusbars can be used easily\&.
.sp
In this text output, colors and icons can be specified through simple bracketed codes\&. Color codes, when passed, will color all text (and icons) following them until another color code is encountered\&. They are called in the following manner\&:
.sp
.RS 4
{#RRGGBB}
.sp
#RRGGBB is a standard hex color-code
.RE
.sp
In a similar manner, minimalist icons may be rendered on the statusbar\&. Icons are called in the following manner\&:
.sp
.RS 4
{i #}
.sp
# should be replaced by the number of the icon as designated by the array at the bottom of icons\&.h\&.
.sp
.RE
.SH "MULTIHEAD SETUP"
\fBAlopex\fR offers support for 16 external displays\&. Auto\-detection and setup of external displays is not supported, but is planned for a future release\&.
.sp
Along with being assigned to tags, each client is given an identifier which determines on what display the client will appear\&. Should the number applied to the client exceed the number of the highest display available, that client will appear on the highest numbered display available\&.
.sp
.RE
.SH "SEE ALSO"
\fBalopex\&.config\fR(5) \fBalopex\&.icons\fR(5)
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










































































































































Deleted alopex.c.

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
/**************************************************************************\
* ALOPEX - a tiny tabbed tagging tiling wm
*
* Author: Jesse McClure, copyright 2012-2013
* License: GPLv3
*
* Based on code from TinyWM by Nick Welch <mack@incise.org>, 2005,
* with coode influence from DWM by the Suckless team (suckless.org),
* and concepts inspired by i3 (i3wm.org).
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*
\**************************************************************************/


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <locale.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/extensions/Xrandr.h>

#define MAX(a,b)	((a)>(b) ? (a) : (b))

#define FLAG_ANY		0xFFFF
#define FLAG_FLOATING	0x0010
#define FLAG_TRANSIENT	0x0030
#define FLAG_FULLSCREEN	0x0040
#define FLAG_TOPSTACK	0x0080
#define FLAG_URG_HINT	0x0400
#define FLAG_FOC_HINT	0x0300
#define FOCUS_NOINPUT	0x0000
#define FOCUS_PASSIVE	0x0100
#define FOCUS_LOCAL		0x0200
#define FOCUS_GLOBAL	0x0300

enum { Background, Default, Occupied, Selected, Urgent, Title,
	TabFocused, TabFocusedBG, TabTop, TabTopBG, TabDefault, TabDefaultBG,
	TagLine, LASTColor };
enum { MOff, MMove, MResize };

typedef struct {
	unsigned int mod;
	KeySym keysym;
	void (*func)(const char *);
	const char *arg;
} Key;

typedef struct {
	unsigned int mod, button;
	void (*func)(const char *);
	const char *arg;
} Button;

typedef struct {
	const char *name, *class;
	int tags, flags;
} Rule;

#define NO_ICON		-1
typedef struct {
	const char *pre;
	int icon;
	const char *post;
} Tagcon;

typedef struct Monitor Monitor;
typedef struct Client Client;
struct Client {
	Window win, parent;
	Client *next;
	int x,y,w,h;
	unsigned int tags, flags;
	char *title;
	Monitor *m;
};
struct Monitor {
	Monitor *next;
	Client *master, *stack;
	int x, y, w, h;
	int count;
	Pixmap buf;
	Window bar;
};


/*********************** [1] PROTOTYPES & VARIABLES ***********************/
/* 1.0 EVENT HANDLER PROTOTYPES */
static void buttonpress(XEvent *);
static void buttonrelease(XEvent *);
static void configurenotify(XEvent *);
static void configurerequest(XEvent *);
static void enternotify(XEvent *);
static void expose(XEvent *);
static void keypress(XEvent *);
static void maprequest(XEvent *);
static void motionnotify(XEvent *);
static void propertynotify(XEvent *);
static void unmapnotify(XEvent *);

/* 1.1 BINDABLE FUNCTION PROTOTYPES */
static void fullscreen(const char *);
static void killclient(const char *);
static void mouse(const char *);
static void quit(const char *);
static void spawn(const char *);
static void tag(const char *);
static void tile_conf(const char *);
static void tile(const char *);
static void toggle(const char *);
static void window(const char *);
static void windowlist(const char *);

/* 1.2 ALOPEX INTERNAL PROTOTYPES */
static inline Bool tile_check(Client *, Monitor *);
static int apply_rules(Client *);
static int draw();
static int get_hints(Client *);
static int get_monitors();
static int neighbors(Client *,Bool);
static GC setcolor(int);
static int swap(Client *, Client *);
static int tile_bstack(Monitor *);
static int tile_monocle(Monitor *);
static int tile_rstack(Monitor *);
static Client *wintoclient(Window);
static int xerror(Display *,XErrorEvent *);

/* 1.3 GLOBAL VARIABLES */
#include "icons.h"
#include "theme.h"
#include "config.h"
static Display *dpy;
static int scr;
static Window root;
static Pixmap sbar, iconbuf;
static GC gc,bgc;
static Colormap cmap;
static XColor color;
//static XFontStruct *fontstruct;
static XButtonEvent mouseEvent;
static Monitor *mons = NULL;
static Bool running = True;
static XFontSet xfs;
static int fontheight, barheight, statuswidth = 0, min_len = 2048;
static int mouseMode = MOff, ntilemode = 0;
static Client *clients = NULL, *focused = NULL, *nextwin, *prevwin, *altwin;
static FILE *inpipe;
static const char *noname_window = "(UNNAMED)";
static unsigned int tagsUrg = 0, tagsSel = 1, tagsOcc = 0, maxTiled = 1;
static int RREvent, RRError;
static void (*handler[LASTEvent]) (XEvent *) = {
	[ButtonPress]		= buttonpress,
	[ButtonRelease]		= buttonrelease,
	[ConfigureNotify]	= configurenotify,
	[ConfigureRequest]	= configurerequest,
	[EnterNotify]		= enternotify,
	[Expose]			= expose,
	[KeyPress]			= keypress,
	[MapRequest]		= maprequest,
	[PropertyNotify]	= propertynotify,
	[MotionNotify]		= motionnotify,
	[UnmapNotify]		= unmapnotify,
};

/************************ [2] FUNCTION DEFINITIONS ************************/
/* 2.0 EVENT HANDLERS */

void buttonpress(XEvent *ev) {
	Client *c;
	XButtonEvent *e = &ev->xbutton;
	if (!( (c=wintoclient(e->subwindow)) && e->state) ) return;
	if (c && e->button < 4) {
		focused = c;
		if (c->flags & FLAG_FLOATING) XRaiseWindow(dpy,c->win);
	}
	int i; mouseEvent = *e;
	for (i = 0; i < sizeof(buttons)/sizeof(buttons[0]); i++)
		if ( (e->button == buttons[i].button) && buttons[i].func &&
				buttons[i].mod == ((e->state&~Mod2Mask)&~LockMask) )
			buttons[i].func(buttons[i].arg);
	if (mouseMode != MOff)
		XGrabPointer(dpy,root,True,PointerMotionMask | ButtonReleaseMask,
				GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
	draw();
}

void buttonrelease(XEvent *ev) {
	XUngrabPointer(dpy, CurrentTime);
	mouseMode = MOff;
	tile(tile_modes[ntilemode]);
}

void configurenotify(XEvent *ev) {
	if (ignore_root_resize) return;
	XConfigureEvent *e = &ev->xconfigure;
	if (e->window != root) return;
	get_monitors();
	tile(tile_modes[ntilemode]);
}

void configurerequest(XEvent *ev) {
	XConfigureRequestEvent *e = &ev->xconfigurerequest;
	Client *c;
	if ( (c=wintoclient(e->window)) ) {
		if ( (e->value_mask & CWWidth) && (e->value_mask & CWHeight) ) {
			if ( (e->width==c->m->w) && (e->height==c->m->h) )
				c->flags |= FLAG_FULLSCREEN;
			else
				c->flags &= ~FLAG_FULLSCREEN;
			c->x = e->x; c->y = e->y; c->w = e->width; c->h = e->height;
		}
		draw();
		return;
	}
	XWindowChanges wc;
	wc.x = e->x; wc.y = e->y; wc.width = e->width; wc.height = e->height;
	wc.sibling = e->above; wc.stack_mode = e->detail;
	wc.border_width = borderwidth;
	XConfigureWindow(dpy,e->window,e->value_mask,&wc);
	XFlush(dpy);
}

void enternotify(XEvent *ev) {
	if (!focusfollowmouse) return;
	Client *c = wintoclient(ev->xcrossing.window);
	if (c) { focused = c; draw(); }
}

void expose(XEvent *ev) {
	draw();
}

void keypress(XEvent *ev) {
	unsigned int i;
	XKeyEvent *e = &ev->xkey;
	KeySym keysym = XkbKeycodeToKeysym(dpy,(KeyCode)e->keycode,0,0);
	for (i = 0; i < sizeof(keys)/sizeof(keys[0]); i++) {
		if ( (keysym == keys[i].keysym) && keys[i].func &&
				keys[i].mod == ((e->state&~Mod2Mask)&~LockMask) )
			keys[i].func(keys[i].arg);
	}
}

//TODO: where does this code belong?
static inline Monitor *mouse_mon() {
	Window w; int x,y,n; unsigned int u;
	XQueryPointer(dpy,root,&w,&w,&x,&y,&n,&n,&u);
	Monitor *m;
	for (m = mons; m; m = m->next)
		if (m->x < x && m->x + m->w > x &&
			m->y < y && m->y + m->h > y)
		return m;
	return mons;
}

void maprequest(XEvent *ev) {
//TODO: cleanup needed
	Client *c, *p;
	XWindowAttributes wa;
	XMapRequestEvent *e = &ev->xmaprequest;
	if (!XGetWindowAttributes(dpy,e->window,&wa)||wa.override_redirect) return;
	if (wintoclient(e->window)) return;
	if (!(c=calloc(1,sizeof(Client)))) exit(1);
	c->m = mouse_mon();
	c->win = e->window;
	c->w = wa.width; c->h = wa.height;
	if (c->x < 0) c->x = 0; if (c->y < 0) c->y = 0;
	c->x = (c->m->w - c->w)/2; c->y = (c->m->h - c->h)/2;
	c->tags = (tagsSel & 0xFFFF ? tagsSel &0xFFFF : ~tagsOcc & (tagsOcc + 1));
	apply_rules(c);
	if ( !(tagsSel & 0xFFFF) ) tagsSel |= c->tags;
	if (c->tags == 0) c->tags = 1;
	if ( (c->w==c->m->w) && (c->h==c->m->h) ) c->flags |= FLAG_FULLSCREEN;
	if (XGetTransientForHint(dpy,c->win,&c->parent))
		c->flags |= FLAG_TRANSIENT;
	else
		c->parent = e->parent;
XTextProperty name; char **list = NULL; int n;
XGetTextProperty(dpy,c->win,&name,XA_WM_NAME);
XmbTextPropertyToTextList(dpy,&name,&list,&n);
if (n && *list) {
c->title = strdup(*list);
XFreeStringList(list);
}
else {
if ( (p=wintoclient(c->parent)) ) c->title = strdup(p->title);
else c->title = strdup(noname_window);
}
//	if (!XFetchName(dpy,c->win,&c->title) || c->title == NULL) {
//		if ( (p=wintoclient(c->parent)) ) c->title = strdup(p->title);
//		else c->title = strdup(noname_window);
//	}
	get_hints(c);
	XSelectInput(dpy,c->win,PropertyChangeMask | EnterWindowMask);
	if (clients && attachmode == 1) {
		for (p = clients; p && p->next && !tile_check(p,c->m); p = p->next);
		c->next = p->next; p->next = c;
	}
	else if (clients && attachmode == 2) {
		for (p = clients; p->next; p = p->next); p->next = c;
	}
	else {
		c->next = clients; clients = c;
	}
	XSetWindowBorderWidth(dpy,c->win,borderwidth);
	XRaiseWindow(dpy,c->win);
	if (c->tags & tagsSel) focused = c;
	if (!(c->flags & FLAG_FLOATING)) tile(tile_modes[ntilemode]);
	draw();
	XMapWindow(dpy,c->win);
	draw();
}

void motionnotify(XEvent *ev) {
	int xdiff, ydiff;
	while (XCheckTypedEvent(dpy,MotionNotify,ev));
	XButtonEvent *e = &ev->xbutton;
	xdiff = e->x_root - mouseEvent.x_root;
	ydiff = e->y_root - mouseEvent.y_root;
	if (mouseMode == MMove) {
		XDefineCursor(dpy,focused->win,XCreateFontCursor(dpy,XC_fleur));
		focused->x+=xdiff; focused->y+=ydiff; draw();
	}
	else if (mouseMode == MResize) {
		XDefineCursor(dpy,focused->win,XCreateFontCursor(dpy,XC_sizing));
		focused->w+=xdiff; focused->h+=ydiff; draw();
	}
	focused->flags |= FLAG_FLOATING;
	mouseEvent.x_root+=xdiff; mouseEvent.y_root+=ydiff;
}

void propertynotify(XEvent *ev) {
	XPropertyEvent *e = &ev->xproperty;
	Client *c, *p;
	if (!(c=wintoclient(e->window)) ) return;
	if (e->atom == XA_WM_NAME) {
		XFree(c->title); c->title = NULL;
		XTextProperty name; char **list = NULL; int n;
		XGetTextProperty(dpy,c->win,&name,XA_WM_NAME);
		XmbTextPropertyToTextList(dpy,&name,&list,&n);
		if (n && *list) {
		c->title = strdup(*list);
		XFreeStringList(list);
		}
		else {
		if ( (p=wintoclient(c->parent)) ) c->title = strdup(p->title);
		else c->title = strdup(noname_window);
		}
	}
	else if (e->atom == XA_WM_HINTS) get_hints(c);
	else if (e->atom == XA_WM_CLASS) apply_rules(c);
	else return;
	draw();
	// TODO Size hints for fullscreen?
}

void unmapnotify(XEvent *ev) {
	Client *c,*t;
	if (!(c=wintoclient(ev->xunmap.window)) || ev->xunmap.send_event) return;
	if (c == focused) {
		neighbors(c,False);
		if (nextwin) focused = nextwin;
		else focused = prevwin;
	}
	if (c == clients) clients = c->next;
	else {
		for (t = clients; t && t->next != c; t = t->next);
		t->next = c->next;
	}
	XFree(c->title);
	free(c); c = NULL;
	tile(tile_modes[ntilemode]);
	draw();
}

/* 2.1 BINDABLE FUNCTIONS */

void fullscreen(const char *arg) {
	if (!focused) return;
	focused->flags ^= FLAG_FULLSCREEN;
	XRaiseWindow(dpy,focused->win);
	draw();
}

void killclient(const char *arg) {
	if (!focused) return;
	XEvent ev;
	ev.type = ClientMessage; ev.xclient.window = focused->win;
	ev.xclient.message_type = XInternAtom(dpy,"WM_PROTOCOLS",True);
	ev.xclient.format = 32;
	ev.xclient.data.l[0] = XInternAtom(dpy,"WM_DELETE_WINDOW",True);
	ev.xclient.data.l[1] = CurrentTime;
	XSendEvent(dpy,focused->win,False,NoEventMask,&ev);
}

void mouse(const char *arg) {
	if (arg[0] == 'm') mouseMode = MMove;
	else if (arg[0] == 'r') mouseMode = MResize;
}

void quit(const char *arg) {
	running = False;
}

void spawn(const char *arg) {
	system(arg);
}

void tag(const char *arg) {
	int i = arg[2] - 49;
	if (arg[0] == 's') tagsSel = ((tagsSel & 0xFFFF0000) | (1<<i));
	else if (arg[0] == 'f') tagsSel = ( tagsSel<<16 | tagsSel >>16);
	else if (arg[0] == 't') tagsSel ^= (1<<i);
	else if (arg[0] == 'a' && focused ) focused->tags ^= (1<<i);
	else if (arg[0] == 'm' && focused ) focused->tags = (1<<i);
	tile(tile_modes[ntilemode]);
	Client *c,*t=NULL;
	if (!focused || !(focused->tags & tagsSel)) {
		for (c = clients; c; c = c->next) if (c->tags & tagsSel) {
			if (!t) t = c;
			if (c->flags & FLAG_FULLSCREEN) t = c;
		}
		if (t) focused = t;
	}
	draw();
}

void tile_conf(const char *arg) {
	if (arg[0] == 'i') tilebias += 4;
	else if (arg[0] == 'd') tilebias -= 4;
	else if (arg[0] == '+') stackcount++;
	else if (arg[0] == '-') stackcount--;
	else if (arg[0] == 'a') stackcount = maxTiled;
	else if (arg[0] == 'o') stackcount = 1;
	if (stackcount >= maxTiled) stackcount = maxTiled - 1;
	if (stackcount < 1) stackcount = 1;
	if (tilebias > min_len/2 - win_min) tilebias = min_len/2 - win_min;
	else if (tilebias < win_min - min_len/2) tilebias = win_min - min_len/2;
	tile(tile_modes[ntilemode]);
}

void tile(const char *arg) {
	char mode = arg[0];
	int i;
	Client *c;
	for (i = 0; tile_modes[i]; i++) 
		if (mode == tile_modes[i][0]) ntilemode = i;
	if (mode == 'c')
		mode = tile_modes[(ntilemode=(tile_modes[++ntilemode]?ntilemode:0))][0];
	Monitor *m;
	maxTiled = 0;
	for (i = 0, m = mons; m; i++, m = m->next) m->count = 0;
	for (c = clients; c; c = c->next)
		if (c->tags & tagsSel && !(c->flags & FLAG_FLOATING)) {
			c->m->count++;
			maxTiled = MAX(maxTiled,c->m->count);
		}
	if (maxTiled == 0) return;
	for (i = 0, m = mons; m; i++, m = m->next) {
		if (m->count == 0) continue;
		if (m->count > stackcount + 1) m->count = stackcount + 1;
		if (m->count == 1) tile_monocle(m);
		else if (mode == 'b') tile_bstack(m);
		else if (mode == 'm') tile_monocle(m);
		else if (mode == 'r') tile_rstack(m);
	}
	if (focused) {
		XRaiseWindow(dpy,focused->win);
		for (c = clients; c; c = c->next)
			if ( (c->tags & tagsSel) && (c->flags & FLAG_FLOATING))
				XRaiseWindow(dpy,c->win);
	}
	draw();
}

void toggle(const char *arg) {
	Monitor *m;
	if (arg[0] == 'p') topbar = !topbar;
	else if (arg[0] == 'v') showbar = !showbar;
	else if (arg[0] == 'f' && focused) focused->flags ^= FLAG_FLOATING;
	else if (arg[0] == 'r') ignore_root_resize = !ignore_root_resize;
else if (arg[0] == 'm' ) {
	Client *c;
	if (focused) m = focused->m;
	else m = mouse_mon();
	if (m && m->next) m = m->next;
	else m = mons;
	for (c = clients; c && !tile_check(c,m); c = c->next);
	if (c) focused=c;
}	
	for (m = mons; m; m = m->next)
		XMoveWindow(dpy,m->bar,(showbar ? m->x : -4*mons[0].w),
				(topbar ? 0 : m->h-barheight));
	tile(tile_modes[ntilemode]);
}

void window(const char *arg) {
	if (!focused) return;
	Monitor *m,*mm = mons;
	if (arg[0] == '+' || arg[0] == '-') { /* move to monitor */
		if (arg[0] == '+' && focused->m->next) {
			focused->m = focused->m->next;
		}
		else {
			for (m = mons; m != focused->m; m = m->next) mm = m;
			focused->m = mm;
		}
		tile(tile_modes[ntilemode]);
		return;
	}
	if (arg[2] < 95) {
		neighbors(focused,True);
	}
	else {
		if (focused->flags & FLAG_FLOATING) return;
		neighbors(focused,False);
	}
	Client *t = NULL;
	if (arg[2] == 'p') t = prevwin;
	else if (arg[2] == 'P') t = prevwin;
	else if (arg[2] == 'n') t = nextwin;
	else if (arg[2] == 'N') t = nextwin;
	else if (arg[2] == 'a') t = altwin;
	if (!t) return;
	if (arg[0] == 'f') focused = t;
	else if (arg[0] == 's') { swap(focused, t); focused = t; }
	XRaiseWindow(dpy,focused->win);
	draw();
}

void windowlist(const char *arg) {
	Client *c;
	const char *wlname = "/tmp/alopex_windows";
	FILE *wl = fopen(wlname,"w");
	for (c = clients; c; c = c->next) {
		fprintf(wl,"%p %s\n",c,c->title);
		printf("%p %s\n",c,c->title);
	}
	fclose(wl);
	if ( (wl=popen(arg,"r")) ) {
		if (fscanf(wl,"%p",&c)==1) {
			focused = c;
			if (!(c->tags & tagsSel)) c->tags |= tagsSel;
			draw();
		}
		pclose(wl);
	}
}

/* 2.2 WM INTERNAL FUNCTIONS */

static inline Bool tile_check(Client *c, Monitor *m) {
	return (c&&(c->tags&tagsSel) && !(c->flags&FLAG_FLOATING) && (c->m==m));
}

static int apply_rules(Client *c) {
	XClassHint *hint = XAllocClassHint();
	XGetClassHint(dpy, c->win, hint);
	int i, m;
	const char *rc, *rn, *hc = hint->res_class, *hn = hint->res_name;
	for (i = 0; i < sizeof(rules)/sizeof(rules[0]); i++) {
		rc = rules[i].class; rn = rules[i].name; m = 0;
		if (rc && hc && !strncmp(rc,hc,strlen(rc))) m++;
		if (rn && hn && !strncmp(rn,hn,strlen(rn))) m++;
		if ( (m && !(rc && rn)) || (m == 2) ) {
			if (rules[i].tags > 0) c->tags = rules[i].tags;
			c->flags |= rules[i].flags;
		}
	}
	XFree(hint->res_name); XFree(hint->res_class); XFree(hint);
	return 0;
}

static inline void draw_tab(Pixmap buf, Client *c,int *x,int tw) {
	int col1 = (c->flags & FLAG_URG_HINT ? Urgent : (c==focused?Title:Default));
	int col2 = (c==focused ? TabFocused : ( ((c==c->m->master || c==c->m->stack) && 
			!(tile_modes[ntilemode][0] == 'm')) ? TabTop : TabDefault ));
	XPoint top_pts[6] = { {*x,barheight}, {0,2-barheight}, {2,-2},
		{tw,0}, {2,2}, {0,barheight-2} };
	XPoint bot_pts[6] = { {*x,0}, {0,barheight-3}, {2,2}, {tw,0},
			{2,-2}, {0,3-barheight} };
	*x+=8;
	XFillPolygon(dpy,buf,setcolor(col2+1),(topbar ? top_pts : bot_pts),6,
		Convex,CoordModePrevious);
	top_pts[0].x -=1;
XmbDrawString(dpy,buf,xfs,setcolor(col1),*x,fontheight,c->title,strlen(c->title));
//	XDrawString(dpy,buf,setcolor(col1),*x,fontheight,c->title,strlen(c->title));
	XFillRectangle(dpy,buf,bgc,*x+tw-5,0,tw,barheight);
	XDrawLines(dpy,buf,setcolor(col2),(topbar?top_pts:bot_pts),
			6,CoordModePrevious);
	*x+=tw;
}

static void draw_tabs(Pixmap buf, int x, int w, int mid, Monitor *m) {
	Client *c;
	int count, tab1w, tabw;
	/* get count - skip if zero */
	for (count = 0, c = clients; c; c = c->next) if (tile_check(c,m)) count++;
	if (!count) return;
	/* set tab widths */
	if (tile_modes[ntilemode][0]=='m' || count==1) tab1w = tabw = w/count - 8;
	else { tab1w = mid-x; tabw = (x+w-mid - 2)/(count-1) - 8; }
	if (tabw < 20) tabw = 20;
	/* draw master title and tab */
	for (c = clients; !(tile_check(c,m)); c = c->next);
	draw_tab(buf,c,&x,tab1w);
	if (count == 1) return;
	/* draw stack titles and tabs */
	for (c = c->next; c; c = c->next)
		if (tile_check(c,m)) draw_tab(buf,c,&x,tabw);
}

int draw() {
	tagsUrg &= ~tagsSel; tagsOcc = 0; Monitor *m;
	/* windows */
	Client *stack = clients;
	for (m = mons; m; m = m->next) m->master = m->stack = NULL;
	XSetWindowAttributes wa;
	while (stack) {
		tagsOcc |= stack->tags;
		if (!(stack->tags & tagsSel)) { /* not on selected tag(s) */
			XMoveWindow(dpy,stack->win,-2*mons[0].w,0);
			stack = stack->next; continue;
		}
		else if (!(stack->flags & FLAG_FLOATING)) { /* tiled */
			if (!stack->m->master) stack->m->master = stack;
			else if (!stack->m->stack) stack->m->stack = stack;
			else if (stack->flags & FLAG_TOPSTACK) stack->m->stack = stack;
		}
		stack->flags &= ~FLAG_TOPSTACK;
		if (stack->flags & FLAG_FULLSCREEN)
			XMoveResizeWindow(dpy,stack->win,stack->m->x-borderwidth,
					stack->m->y-borderwidth,stack->m->w,stack->m->h);
		else
			XMoveResizeWindow(dpy,stack->win,stack->x,
					stack->y,stack->w,stack->h);
		if (stack == focused) setcolor(Selected);
		else setcolor(Occupied);
		wa.border_pixel = color.pixel;
		XChangeWindowAttributes(dpy,stack->win,CWBorderPixel,&wa);
		stack = stack->next;
	}
	if (focused) {
		if ( (focused != focused->m->master) && !(focused->flags & FLAG_FLOATING) )
			focused->m->stack = focused;
		if ( (focused->flags & FLAG_FOC_HINT) > 1) {
			XEvent ev;
			ev.type = ClientMessage; ev.xclient.window = focused->win;
			ev.xclient.message_type = XInternAtom(dpy,"WM_PROTOCOLS",True);
			ev.xclient.format = 32;
			ev.xclient.data.l[0] = XInternAtom(dpy,"WM_TAKE_FOCUS",True);
			ev.xclient.data.l[1] = CurrentTime;
			XSendEvent(dpy,focused->win,False,NoEventMask,&ev);
		}
		else {
			XSetInputFocus(dpy,focused->win,RevertToPointerRoot,CurrentTime);
		}
		focused->flags &= ~FLAG_URG_HINT;
	}
	for (m = mons; m ; m = m->next) {
		if (m->stack) m->stack->flags |= FLAG_TOPSTACK;
		/* clear buffers */
		XFillRectangle(dpy,m->buf,setcolor(Background),0,0,m->w,barheight);
	}
	/* tags */
	m = mons; /* tags are drawn on main screen only */
	int i,x=10,w=0,col, tagsAlt = (tagsSel>>16);
	for (i = 0; i < sizeof(tagcons)/sizeof(tagcons[0]); i++) {
		if (!((tagsOcc|tagsSel) & (1<<i))) continue;
		col = (tagsUrg & (1<<i) ? Urgent :
			(tagsOcc & (1<<i) ? Occupied : Default));
		if (focused && focused->tags & (1<<i)) col = Selected;
			w = 0;
			if (tagcons[i].pre) {
XmbDrawString(dpy,m->buf,xfs,setcolor(col),x,fontheight,
tagcons[i].pre,strlen(tagcons[i].pre));
w += XmbTextEscapement(xfs,tagcons[i].pre,strlen(tagcons[i].pre));
//				XDrawString(dpy,m->buf,setcolor(col),x,fontheight,
//						tagcons[i].pre,strlen(tagcons[i].pre));
//				w += XTextWidth(fontstruct,tagcons[i].pre,strlen(tagcons[i].pre));
			}
			if (tagcons[i].icon > -1) {
			XFillRectangle(dpy,iconbuf,bgc,0,0,iconwidth,iconheight);
			XDrawPoints(dpy,iconbuf,setcolor(col),icons[tagcons[i].icon].pts,
					icons[tagcons[i].icon].n,CoordModeOrigin);
			XCopyArea(dpy,iconbuf,m->buf,gc,0,0,iconwidth,iconheight,
					x+w,(barheight-iconheight)/2);
			w += iconwidth;
			}
			if (tagcons[i].post) {
					w += 2;
XmbDrawString(dpy,m->buf,xfs,setcolor(col),x+w,fontheight,
tagcons[i].post,strlen(tagcons[i].post));
w += XmbTextEscapement(xfs,tagcons[i].post,strlen(tagcons[i].post));
//					XDrawString(dpy,m->buf,setcolor(col),x+w,fontheight,
//						tagcons[i].post,strlen(tagcons[i].post));
//					w += XTextWidth(fontstruct,tagcons[i].post,strlen(tagcons[i].post));
			}
			setcolor(TagLine);
			if (tagsSel & (1<<i)) {
				XDrawLine(dpy,m->buf,gc,x-2,barheight-1,x+w+2,barheight-1);
				XDrawPoint(dpy,m->buf,gc,x-2,barheight-2);
				XDrawPoint(dpy,m->buf,gc,x+w+2,barheight-2);
			}
			if (tagsAlt & (1<<i)) {
				XDrawLine(dpy,m->buf,gc,x-2,0,x+w+2,0);
				XDrawPoint(dpy,m->buf,gc,x-2,1);
				XDrawPoint(dpy,m->buf,gc,x+w+2,1);
			}
			x+=w+5;
	}
	if ( (x+=5) < tagspace ) x = tagspace; /* add padding */
	/* titles / tabs */
	for (i = 0, m = mons; m; i++, m = m->next)
		draw_tabs(m->buf,(i?2:x),m->w-(i?8:x+statuswidth+10),
				m->w/2+tilebias-6,m);
	/* status */
	if (statuswidth)
		XCopyArea(dpy,sbar,mons[0].buf,gc,0,0,statuswidth,
				barheight,mons[0].w-statuswidth,0);
	for (m = mons; m; m = m->next)
		XCopyArea(dpy,m->buf,m->bar,gc,0,0,m->w,barheight,0,0);
	XFlush(dpy);
	return 0;
}

int get_hints(Client *c) {
	XWMHints *hint;
	if ( (hint=XGetWMHints(dpy,c->win)) ) {
		if (hint->flags & XUrgencyHint) {
			tagsUrg |= c->tags;
			c->flags |= FLAG_URG_HINT;
		}
		else if (hint->flags & InputHint && !hint->input) {
			c->flags |= FLAG_FOC_HINT; /* TODO: termine Local vs Global */
		}
		XFree(hint);
	}
	return 0;
}

int get_monitors() {
	/* free current monitors */
	Monitor *m; Client *c;
	for (m = mons; m; m = m->next) {
		XFreePixmap(dpy,m->buf);
		XDestroyWindow(dpy,m->bar);
	}
	if (mons) free(mons);
	/* get xrandr info */
	XSetWindowAttributes wa;
	wa.override_redirect = True;
	wa.event_mask = ExposureMask;
	XRRScreenResources *xrr_sr = XRRGetScreenResources(dpy,root);
	XRROutputInfo *xrr_out_info;
	XRRCrtcInfo *xrr_crtc_info;
	int i, nscr = xrr_sr->noutput;
	mons = (Monitor *) calloc(nscr,sizeof(Monitor));
	/* loop through monitors */
	for (i = 0; i < nscr; i++) {
		xrr_out_info = XRRGetOutputInfo(dpy, xrr_sr, xrr_sr->outputs[i]);
		if (!xrr_out_info->crtc) {
			nscr = i;
			mons = (Monitor *) realloc(mons,nscr * sizeof(Monitor));
			XRRFreeOutputInfo(xrr_out_info);
			break;
		}
		xrr_crtc_info = XRRGetCrtcInfo(dpy, xrr_sr, xrr_out_info->crtc);
		m = &mons[i];
		m->x = xrr_crtc_info->x;
		m->y = xrr_crtc_info->y;
		m->w = xrr_crtc_info->width;
		m->h = xrr_crtc_info->height;
		min_len = (min_len > m->w ? m->w : min_len);
		min_len = (min_len > m->h ? m->h : min_len);
		XRRFreeCrtcInfo (xrr_crtc_info);
		XRRFreeOutputInfo(xrr_out_info);
		m->bar = XCreateSimpleWindow(dpy,root,m->x,
			(topbar ? m->y : m->h - barheight), m->w,barheight,0,0,0);
		m->buf = XCreatePixmap(dpy,root,m->w,barheight,DefaultDepth(dpy,scr));
		XChangeWindowAttributes(dpy,m->bar,CWOverrideRedirect|CWEventMask,&wa);
		XMapWindow(dpy,m->bar);
	}
	XRRFreeScreenResources(xrr_sr);
	for (i = 0; i < nscr - 1; i++) mons[i].next = &mons[i+1];
	for (c = clients; c; c = c->next) {
		for (m = mons; m; m = m->next)
			if (m->x <= c->x && m->x + m->w > c->x &&
					m->y <= c->y && m->y + m->h > c->y)
				c->m = m;
	}
#ifdef WALLPAPER
	system(CMD(WALLPAPER));
#endif
	return 0;
}

int neighbors(Client *c, Bool floaters) {
	prevwin = NULL; nextwin = NULL; altwin = NULL;
	if (!(c->tags & tagsSel)) return -1;
	Client *stack;
	if (floaters) {
		for (stack = clients; stack && stack != c; stack = stack->next)
			if (stack&&(stack->tags&tagsSel) && (stack->m==c->m)) prevwin = stack; 
		if (!stack) return -1;
		for (nextwin = stack->next; nextwin; nextwin = nextwin->next)
			if (stack&&(stack->tags&tagsSel) && (stack->m==c->m)) break;
	}
	else {
		for (stack = c->m->master; stack && stack != c; stack = stack->next)
			if (tile_check(stack,c->m)) prevwin = stack;
		if (!stack) return -1;
		for (nextwin = stack->next; nextwin; nextwin = nextwin->next)
			if (tile_check(nextwin,c->m)) break;
		if (c->m && c->m->master == focused) altwin = c->m->stack;
		else if (c->m) altwin = c->m->master;
	}
	return 0;
}

GC setcolor(int col) {
	XAllocNamedColor(dpy,cmap,colors[col],&color,&color);
	XSetForeground(dpy,gc,color.pixel);
	return gc;
}

int status(char *msg) {
	char col[8] = "#000000", *t,*c = msg;
	int l, arg, lastwidth = statuswidth;
	statuswidth = 0;
	XFillRectangle(dpy,sbar,setcolor(Background),0,0,mons[0].w/2,barheight);
	setcolor(Default);
	while (*c != '\n') {
		if (*c == '{') {
			if (*(++c) == '#') {
				strncpy(col,c,7);
				XAllocNamedColor(dpy,cmap,col,&color,&color);
				XSetForeground(dpy,gc,color.pixel);
			}
			else if (*c == 'i' && sscanf(c,"i %d",&arg) == 1) {
				XFillRectangle(dpy,iconbuf,bgc,0,0,iconwidth,iconheight);
				XDrawPoints(dpy,iconbuf,gc,icons[arg].pts,icons[arg].n,
					CoordModeOrigin);
				XCopyArea(dpy,iconbuf,sbar,gc,0,0,iconwidth,iconheight,
						statuswidth,(barheight-iconheight)/2);
				statuswidth+=iconwidth+1;
			}
			c = strchr(c,'}')+1;
		}
		else {
			if ( (t=strchr(c,'{'))==NULL) t = strchr(c,'\n');
			if ( (l = (t == NULL ? 0 : t - c) ) ) {
XmbDrawString(dpy,sbar,xfs,gc,statuswidth,fontheight,c,l);
statuswidth += XmbTextEscapement(xfs,c,l);
//				XDrawString(dpy,sbar,gc,statuswidth,fontheight,c,l);
//				statuswidth += XTextWidth(fontstruct,c,l);
			}
			c+=l;
		}
	}
	if (statuswidth == lastwidth) {
		XCopyArea(dpy,sbar,mons[0].bar,gc,0,0,statuswidth,barheight,
				mons[0].w-statuswidth,0);
		XFlush(dpy);
	}
	else draw();
	return 0;
}

int swap(Client *a, Client *b) {
	if (!a || !b) return -1;
	Client t;
	t.title = a->title; a->title=b->title; b->title = t.title;
	t.tags = a->tags; a->tags = b->tags; b->tags = t.tags;
	t.flags = a->flags; a->flags = b->flags; b->flags = t.flags;
	t.win = a->win; a->win = b->win; b->win = t.win;
	t.m = a->m; a->m = b->m; b->m = t.m;
	if (a->flags & FLAG_TOPSTACK) {
		a->flags &= ~FLAG_TOPSTACK; b->flags |= FLAG_TOPSTACK;
	}
	else if (b->flags & FLAG_TOPSTACK) {
		b->flags &= ~FLAG_TOPSTACK; a->flags |= FLAG_TOPSTACK;
	}
	return 0;
}

#define TILE_CALC	\
	int x = m->x + tilegap, w = m->w - 2*(tilegap + borderwidth),\
		y = m->y + (showbar ? (topbar ? barheight : 0) : 0) + tilegap,\
		h = m->h - (showbar ? barheight : 0) - 2*(tilegap + borderwidth);

int tile_bstack(Monitor *m) {
	TILE_CALC
	Client *c, *t = NULL;
	for (c = clients; !tile_check(c,m); c = c->next);
	int wh = (h - tilegap)/2 - borderwidth;
	int ww = w/(m->count - 1) - tilegap/2;
	c->x = x; c->y = y;	c->w = w; c->h = wh + tilebias;
	int i = 0;
	while ( (c=c->next) ) {
		if (!tile_check(c,m)) continue;
		c->x = x + i*(ww + tilegap + borderwidth);
		c->y = y + wh + tilegap + 2*borderwidth + tilebias;
		c->w = MAX(ww - borderwidth, win_min);
		c->h = wh - tilebias;
		if (!t && i == m->count - 2) t = c;
		i = ( i == m->count - 2 ? m->count - 2 : i + 1);
	}
	while (t) {
		if (tile_check(t,m)) t->w = MAX(x + w - t->x,win_min);
		t = t->next;
	}
	return 0;
}

int tile_monocle(Monitor *m) {
	TILE_CALC
	Client *c = clients;
	for (c = clients; !tile_check(c,m); c = c->next);
	if (c) do {
		if (!tile_check(c,m)) continue;
		c->x = x; c->y = y;	c->w = w; c->h = h;
	} while ( (c=c->next) );
	return 0;
}

int tile_rstack(Monitor *m) {
	TILE_CALC
	Client *c, *t = NULL;
	for (c = clients; !tile_check(c,m); c = c->next);
	int ww = (w - tilegap)/2 - borderwidth;
	int wh = h/(m->count - 1) - tilegap/2;
	c->x = x; c->y = y; c->w = ww + tilebias; c->h = h;
	int i = 0;
	while ( (c=c->next) ) {
		if (!tile_check(c,m)) continue;
		c->x = x + ww + tilegap + 2*borderwidth + tilebias;
		c->y = y + i*(wh + tilegap + borderwidth);
		c->w = ww - tilebias;
		c->h = MAX(wh - borderwidth,win_min);
		if (!t && i == m->count - 2) t = c;
		i = ( i == m->count - 2 ? m->count - 2 : i + 1);
	}
	while (t) {
		if (tile_check(t,m)) t->h = MAX(y + h - t->y, win_min);
		t = t->next;
	}
	return 0;
}

Client *wintoclient(Window w) {
	Client *c;
	for (c = clients; c && c->win != w; c = c->next);
	return c;
}

int xerror(Display *d, XErrorEvent *ev) {
	char msg[1024];
	XGetErrorText(dpy,ev->error_code,msg,sizeof(msg));
	fprintf(stderr,"[ALOPEX] (%d:%d) %s\n",ev->request_code,ev->error_code,msg);
	return 0;
}

int main(int argc, const char **argv) {
	if (argc > 1) inpipe = popen(argv[1] ,"r");
	else inpipe = popen("while :; do date \"+%I:%M %p\"; sleep 10; done","r");
	/* init X */
	if (!(setlocale(LC_CTYPE,"") && XSupportsLocale())) return 1;
	if (!XSetLocaleModifiers("")) return 2;
	if (!(dpy=XOpenDisplay(0x0))) return 3;
	if (!(XRRQueryExtension(dpy,&RREvent,&RRError))) return 4;
	scr = DefaultScreen(dpy);
	root = DefaultRootWindow(dpy);
	XSetErrorHandler(xerror);
	XDefineCursor(dpy,root,XCreateFontCursor(dpy,alopex_cursor));
	/* gc init */
	cmap = DefaultColormap(dpy,scr);
	XColor color;
	XGCValues val;
char **missing, **names, *def; int nmiss;
xfs = XCreateFontSet(dpy,(char *) font,&missing,&nmiss,&def);
if (!xfs) return 5;
XFontStruct **fss;
XFontsOfFontSet(xfs,&fss,&names);
if (missing) XFreeStringList(missing);
fontheight = fss[0]->ascent;
barheight = fss[0]->ascent+fss[0]->descent+2;
//	val.font = XLoadFont(dpy,font);
//	fontstruct = XQueryFont(dpy,val.font);
//	fontheight = fontstruct->ascent+1;
//	barheight = fontstruct->ascent+fontstruct->descent+2;
	gc = XCreateGC(dpy,root,0,&val);
	bgc = DefaultGC(dpy,scr);
	XAllocNamedColor(dpy,cmap,colors[Background],&color,&color);
	XSetForeground(dpy,bgc,color.pixel);
	/* monitors, bar windows, and buffers */
	get_monitors();
	sbar = XCreatePixmap(dpy,root,mons[0].w/2,barheight,DefaultDepth(dpy,scr));
	iconbuf = XCreatePixmap(dpy,root,iconwidth,iconheight,
			DefaultDepth(dpy,scr));
	/* configure root window */
	XSetWindowAttributes wa;
	wa.event_mask = ExposureMask |FocusChangeMask | SubstructureNotifyMask |
			ButtonReleaseMask | PropertyChangeMask | SubstructureRedirectMask |
			StructureNotifyMask;
	XChangeWindowAttributes(dpy,root,CWEventMask,&wa);
	XSelectInput(dpy,root,wa.event_mask);
	//XRRSelectInput(dpy,root,RREvent & RRScreenChangeNotify);
	/* key and mouse bindings */
	unsigned int mods[] = {0, LockMask, Mod2Mask, LockMask|Mod2Mask};
	KeyCode code;
	XUngrabKey(dpy,AnyKey,AnyModifier,root);
	int i,j;
	for (i = 0; i < sizeof(keys)/sizeof(keys[0]); i++)
		if ( (code=XKeysymToKeycode(dpy,keys[i].keysym)) )
			for (j = 0; j < 4; j++)
				XGrabKey(dpy,code,keys[i].mod|mods[j],root,True,
						GrabModeAsync,GrabModeAsync);
	for (i = 0; i < sizeof(buttons)/sizeof(buttons[0]); i++)
		if (buttons[i].mod) for (j = 0; j < 4; j++)
			XGrabButton(dpy,buttons[i].button,buttons[i].mod|mods[j],root,True,
					ButtonPressMask,GrabModeAsync,GrabModeAsync,None,None);
	/* main loop */
	draw();
	XEvent ev;
	int xfd, sfd;
	fd_set fds;
	sfd = fileno(inpipe);
	xfd = ConnectionNumber(dpy);
	char *line = (char *) calloc(max_status_line+1,sizeof(char));
	while (running) {
		FD_ZERO(&fds);
		FD_SET(sfd,&fds);
		FD_SET(xfd,&fds);
		select(xfd+1,&fds,0,0,NULL);
		if (FD_ISSET(xfd,&fds)) while (XPending(dpy)) {
			XNextEvent(dpy,&ev);
			if (ev.type == (RREvent & RRScreenChangeNotify)) get_monitors();
			else if (handler[ev.type]) handler[ev.type](&ev);
		}
		if (FD_ISSET(sfd,&fds)) {
			if (fgets(line,max_status_line,inpipe))
				status(line);
		}
	}
	/* clean up */
	Monitor *m;
	for (m = mons; m; m = m->next) {
		XFreePixmap(dpy,m->buf);
		XDestroyWindow(dpy,m->bar);
	}
	free(mons);
	XDestroyWindow(dpy,sbar);
	free(line);
XFreeFontSet(dpy,xfs);
//	XFreeFontInfo(NULL,fontstruct,1);
	XUnloadFont(dpy,val.font);
	XCloseDisplay(dpy);
	return 0;
}

// vim: ts=4	

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Deleted alopex.config.5.

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
'\" t
.\"     Title: alopex.config
.\"    Author: [Sam Stuewe]
.\"      Date: 2013-04-22
.\"    Manual: \ \&
.\"    Source: \ \& 2.0
.\"  Language: English
.\"
.TH "ALOPEX\&.CONFIG" "5" "2013-04-22" "\ \& 2\&.0" "\ \&"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.nh
.ad l
.\"
.\" <- Main Content ->
.SH "NAME"
alopex.config \- Configuration Options
.SH "SYNOPSIS"
.sp
alopex\&.config
.SH "DESCRIPTION"
.sp
A custom configuration for \fBalopex\fR can be placed at \fI$XDG_CONFIG_HOME/alopex/config.h\fR or \fI$HOME/.alopex_conf.h\fR\&. It is a C header file, editable with your favorite text editor\&. Once editing is finished, \fBalopex\fR must be (re)built using the custom configuration\&.
.SH "APPEARANCE SETTINGS"
.PP
font
.RS 4
An xfontsel value of a valid bitmap font to be used on the statusbar\&.
.RE
.PP
*tile_modes
.RS 4
Determines the default status, cycle order and availability of the tiling modes\&. The last value in the array should be \fINULL\fR\&. The first mode in the array will be the default mode when \fBalopex\fR starts\&; the order of the modes when cycling is determined by the order of the modes listed in the array\&. Removing a mode from the array effectively disables that mode's usage\&.
.RE
.PP
tagcons
.RS 4
Determines the appearance of tags on the statusbar\&. Each sub-array is made up of three values\&: a text prefix, an icon and a text suffix\&. Each text affix must be quoted, the icon should not be\&. Replacing either text affix with \fINULL\fR (not quoted), will result in the replaced string not appearing\&. Replacing an icon identifier with \fI-1\fR or \fINO_ICON\fR will result in no icon being displayed\&. See \fBalopex\&.icons\fR(5) for more information\&.
.RE
.PP
alopex_cursor
.RS 4
The X11 cursor designated for \fBalopex\fR to render\&. (Defaults to \fIXC_left_ptr\fR)
.RE
.PP
borderwidth
.RS 4
Width of a border to be drawn around each window\&. Setting to 0 results in no border being drawn\&. (Defaults to 0)
.RE
.PP
tilegap
.RS 4
Toggles the "seemless tab mode"\&. Values above 0 will enable the use of nicer\-looking tabs with a gap between statusbar and the windows\&. (Defaults to 0)
.RE
.PP
tagspace
.RS 4
Sets the minimum space on the left of the statusbar of which the master tab will stay to the right\&. 0 will keep the master tab flush with the right\-most displayed tag\&. (Defaults to 0)
.RE
.PP
max_status_line
.RS 4
The maximum input length you might feed to the stdin reader\&. (Defaults to 256)
.RE
.PP
win_min
.RS 4
The smallest allowable width or height of a window\&. This effects the increasing and decreasing of \fItilebias\fR and can protect windows from being "crushed" when too many are open\&. (Defaults to 20)
.RE
.PP
focusfollowmouse
.RS 4
Whether window focus can be grabbed by mouse\-movement\&. (Defaults to False)
.RE
.PP
showbar
.RS 4
Whether the statusbar should be displayed\&. (Defaults to True)
.RE
.PP
topbar
.RS 4
Whether or not the statusbar should be displayed at the top or bottom of the screen\&. True displays the bar at the top\&; False displays the bar at the bottom\&. (Defaults to True)
.RE
.PP
tilebias
.RS 4
The number of pixels that the master area will be increased in size at the expense of the same number of pixels being taken from the stack section\&. 0 leaves the two sections at parity\&. (Defaults to 0)
.RE
.PP
attachmode
.RS 4
Where new new windows will be placed when created\&. 0 places them at the master section\&; 1 places them at the top of the stack\&; 2 places them at the bottom of the stack\&. (Defaults to 0)
.RE
.PP
stackcount
.RS 4
How many windows can be visible in the stack region at a given time\&. (Defaults to 3)
.RE
.SH "BEHAVIORAL ARRAYS"
.PP
\fIKey\fR
.RS 4
Defines the available keybinds\&. Each keybind has four comma\-separated components\&: the modifier, the key, the function and the argument\&.
.sp
Four modifiers are defined by default, \fIKEY1\fR through \fIKEY4\fR (Super, Alternate, Control and Shift respectively)\&. Using multiple modifiers for a single keybind can be achieved by listing multiple modifiers separated by \&|s\&. To omit the need for a modifier (useful for media keys), use 0 for the value of the modifier.
.sp
The key may be specified either by hex definition or by X11 Keysym\&. See \fBxev\fR(1) for more information on how to discover these values\&.
.sp
The following functions are available with an explanation of their accepted arguments\&:
.sp
.RS 4
spawn \- run a program
.RS 8
.nf
CMD("program \-flags \-\-switches arguments")
CMD(FUNCTION)
.fi
.RE
.sp
quit \- cleanly exit \fBalopex\fR
.RS 8
NULL
.RE
.sp
killclient \- kill the focused program
.RS 8
NULL
.RE
.sp
fullscreen \- toggle the focused client fullscreen
.RS 8
NULL
.RE
.sp
toggle
.RS 8
.nf
"floating"       \-\- toggle focused client to floating mode
"place bar"      \-\- toggle statusbar between the top and bottom
"visible bar"    \-\- toggle visibility of the statusbar
"monitor focus"  \-\- toggle focus between monitors
.fi
.RE
.sp
tile \- modify tile mode properties
.RS 8
.nf
"cycle"    \-\- cycle through available tiling layouts
"bstack"   \-\- switch to the bstack tiling layout
"rstack"   \-\- switch to the rstack tiling layout
"monocle"  \-\- switch to the monocle layout
.fi
.RE
.sp
tile_conf \- modify tiling appearance
.RS 8
.nf
"increase"  \-\- increment \fItilebias\fR in favor of the master section
"decrease"  \-\- increment \fItilebias\fR in favor of the stack
"+"         \-\- increase the number of visible windows in the stack
"-"         \-\- decrease the number of visible windows in the stack
"all"       \-\- make all windows in the stack section visible
"one"       \-\- only allow one window in the stack to be visible
.fi
.RE
.sp
tag \- perform tagging operations
.RS 8
"flip"  \-\- switch between views
.RE
.sp
window \- focus and move windows
.RS 8
.nf
"f prev"  \-\- focus previous
"f next"  \-\- focus next
"f alt"   \-\- focus alternate
"s prev"  \-\- swap window with previous
"s next"  \-\- swap window with next
"s alt"   \-\- swap window with alternate
"+"       \-\- Increase focused window's monitor identifier
"-"       \-\- Decrease focused window's monitor identifier
.fi
.sp
Capitalizing "Next" and "Prev" include floating windows
.RE
.RE
.sp
A special definition after the modifier masks efficiently defines keybinds for tagging operations\&. When calling this special function, two comma\-separated components must be specified\&: the key and the tag\&. They key is an X11 keysym, and the tag is the ordinal number of the tag in the \fItagcons\fR array with the first position being labeled "1"\&.
.sp
Unlike other keybind declarations, \fITagKey\fR declarations are not surrounded by brackets ('{' and '}'), they are called in the following manner\&:
.RS 4
.sp
TagKey(     KEYSYM,       TAGNUMBER     )
.RE
.sp
There should be one declaration for each tag in the \fItagcons\fR array\&.
.RE
.RE
.RE
.PP
\fIButton\fR
.RS 4
Defines actions to be bound to mouse buttons\&. As with the \fIKey\fR array, it is made up of four comma\-separated components\&: the modifier, the button, the function and the argument\&.
.sp
All four pre\-defined modifiers are accepted\&. The button is specified by numeral only \fI1\fR through \fI7\fR, by defalt\&. All functions and arguments from the \fIKey\fR array are available plus one additional function\&:
.RS 4
.sp
mouse
.RS 8
.nf
"move"    \-\- drag window
"resize"  \-\- resize window
.fi
.RE
.RE
.RE
.sp
.PP
\fIRule\fR
.RS 4
Defines window management rules\&. This array is made up of four comma\-separated components\&: the name, the class, tags and flags\&.
.sp
The name and class refer to X11's values of \fBresource name\fR and \fBresource class\fR from \fIWM_CLASS\fR\&. To determine their values, see \fBxprop\fR(1)\&. Either name or class may be replaced by NULL to ignore their values\&. If both are specified, then the rule will only be applied in cases where both values match\&.
.sp
The tags allow the user to specify windows which match the name and class conditions to be automatically assigned given tags\&.
.sp
.RS 4
These tag declarations are sets of 16 bits where each bit represents the client's assignment to a particular tag (0 meaning unassigned and 1 meaning assigned)\&. For example, if a window were to be assigned to tag 1, and another to be assigned to all 16 tags, they would be represented (in binary) as "0000000000000001" and "1111111111111111"\&. Because C cannot represent binary numbers, these two sequences can be represented in decimal, hex, bitwise-or statements or sums of powers of 2\&:
.sp
.nf
1           65535
0x0001      0xFFFF
(1<<0)      (1<<0) | (1<<1) ... (1<<15)
2^0         2^0 + 2^1 ... 2^15
.fi
.sp
To not assign tags to matched windows, use a value of 0\&.
.RE
.sp
The flags refer to special properties that can be assigned to windows for particular behaviors\&:
.RS 4
.sp
.nf
FLAG_FLOATING    \-\- force floating mode
FLAG_FULLSCREEN  \-\- force fullscreen mode
FLAG_URG_HINT    \-\- give window urgent status upon opening
.fi
.sp
To not assign any special properties, use 0\&.
.RE
.RE
.SH "FUNCTION DEFINITIONS"
.PP
\fIXRANDR_CMD\fR
.RS 4
The command to use for managing external monitors\&. The default value is not sane for all setups\&; It must be customized for your setup to be functional\&. See \fBxrandr\fR(1) for more information\&.
.PP
.RE
\fIWALLPAPER\fR
.RS 4
An optional command to be run in concert with \fIXRANDR_CMD\fR to keep the wallpaper looking clean even through managing external displays\&.
.RE
.PP
\fIPer-User\fR
.RS 4
.sp
#define FUNCTION    "command -flags --switches arguments"
.sp
Using the above structure, you would be able to use \fICMD(FUNCTION)\fR as an argument for the \fIspawn\fR function in the \fIKey\fR array\&.
.RE
.SH "SPECIAL INCLUDES"
.PP
\fIKeysyms\fR
.RS 4
.sp
By including the following line, you will be able to use XF86 keysyms rather than just X11 keysyms\&:
.sp
.RS 4
#include <X11/XF86keysym.h>
.RE
.RE
.SH "SEE ALSO"
.sp
\fBalopex\fR(1) \fBalopex\&.icons\fR(5)
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




























































































































































































































































































































































































































































































































































































Deleted alopex.icons.5.

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
'\" t
.\"     Title: alopex.icons
.\"    Author: [Sam Stuewe]
.\"      Date: 2013-04-22
.\"    Manual: \ \&
.\"    Source: \ \& 2.0
.\"  Language: English
.\"
.TH "ALOPEX\&.ICONS" "5" "2013-04-22" "\ \& 2\&.0" "\ \&"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.nh
.ad l
.\"
.\" <- Main Content ->
.SH "NAME"
alopex.icons \- Custom Iconsets
.SH "SYNOPSIS"
.sp
alopex\&.icons
.SH "DESCRIPTION"
.sp
A custom iconset for \fBalopex\fR can be placed at \fI$XDG_CONFIG_HOME/alopex/icons.h\fR or \fI$HOME/.alopex_icons.h\fR\&. It is a C header file, editable with your favorite text editor\&. Once editing is finished, \fBalopex\fR must be (re)built using the custom iconset\&.
.SH "SETTINGS"
.PP
By default, icons are 10 pixels by 10 pixels\&. However, this can easily be changed by modifying the following values\&:
.sp
.RS 4
.nf
iconwidth
iconheight
.fi
.RE
.SH "DECLARATIONS"
.PP
Each icon is defined separately in an array which specifies which pixels will be rendered as active which will not\&. This array is made up of a set of sub\-arrays\&. Each sub\-array is a coordinate pair of active pixels\&. A template icon is provided that, if used, would be a solid 10 by 10 square block\&. This template can easily be copied and modified\&.
.SH "ORDER"
.PP
At the bottom of the icons\&.h file, the \fIIcon\fR array establishes the ordinal designation of each icon and which icons are available\&. These designations are made in the following manner\&:
.RS 4
.sp
[#]     = MAKE_ICON(icon_name),
.sp
# refers to the ordinal designation, and, of course, icon_name refers to the name given to the specific icon array\&.
.RE
.SH "SEE ALSO"
.sp
\fBalopex\fR(1) \fBalopex\&.config\fR(5)
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
































































































Deleted config.h.

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
/* copyright J.McClure 2012-2013, see alopex.c or COPYING for details */


static const char font[] =
	"-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-*";
static const char *tile_modes[] =
	{"rstack", "bstack","monocle", NULL};

/* each tagcon entry defines and icon and/or a name for each tag.
   You may use any combination of entries for any tags including
   using names (pre/post) for some, icons for others, and both for
   yet others.  Technically you can have usable tags without any
   indicator text or icon, which may not have practical purpose
   other than "hiding" client windows.  For no icon use NO_ICON
   or a -1, for no text use NULL. */
static const Tagcon tagcons[] = {
	/* pre		icon		post */
	{ NULL,		20,			"one"},
	{ NULL,		21,			"two" },
	{ NULL,		22,			"three" },
	{ "4:",		NO_ICON,	"four" },
	{ "5:",		NO_ICON,	"five" },
	{ "6:",		NO_ICON,	"six" },
};

static const char	alopex_cursor		= XC_left_ptr;
static const int	borderwidth			= 0;
/* set gap between the windows */
static const int	tilegap				= 0;
/* set a minimum space on the left of the bar that the master tab will
   stay to the right of.  Setting to zero will keep the master tab flush
   against the last displayed tag name */
static const int	tagspace			= 0;
/* set to the maximum input you might feed to the stdin reader */
static const int	max_status_line		= 256;
/* smallest allowable width or height for a window
   This effects increasing and decreasing the tilebias, and can protect
   windows from getting completely "crushed" when too many are opened
   in rstack/bstack modes */
static const int	win_min				= 20;
static const Bool	focusfollowmouse	= False;
static Bool			showbar				= True;
static Bool			topbar				= True;
/* tilebias is set as a number of pixels to increase the master (and thus
   decrease the stack) from half the screen width.  Zero means the two will
   share the screen equally. */
static int			tilebias			= 0;
/* attachmode determines where new windows will be placed.
   0 = master, 1 = aside (top of stack), 2 = bottom */
static const int	attachmode			= 0;
/* stackcount sets how many clients can me visible in the stack region.
   For "ttwm" tiling mode, set stackcount to 1.  The value can be changed
   via a key binding (default Mod+ or Mod-). */
static int			stackcount			= 3;
/* Workaround for SDL games: set to true if you only ever use one
   monitor or otherwise want alopex to ignore any reconfigurations of
   the root window.  */
static Bool			ignore_root_resize	= False;

#define DMENU		"dmenu_run -fn \"-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-*\" -nb \"#101010\" -nf \"#484862\" -sb \"#080808\" -sf \"#FFDD0E\""

#ifdef THEME_NAME
#define TERM		"urxvt -name " THEME_NAME
#else
#define TERM		"urxvt" 		/* or "urxvtc","xterm","terminator",etc */
#endif

#define CMD(app)	app "&"

/* these are just examples - be sure to edit for your setup.
   Uncomment and define WALLPAPER suitably to have the wallpaper */

#define XRANDR_CMD		"xrandr --output LVDS1 --auto --output VGA1 --auto --left-of LVDS1"
//#define WALLPAPER		"feh --bg-scale ~/images/bg.jpg"

/* key definitions */
#define KEY1 Mod4Mask
#define KEY2 Mod1Mask
#define KEY3 ControlMask
#define KEY4 ShiftMask
#define TagKey(KEY,TAG) \
	{ KEY1,				KEY,		tag,	"s " TAG }, \
	{ KEY1|KEY2,		KEY,		tag,	"t " TAG }, \
	{ KEY1|KEY3,		KEY,		tag,	"m " TAG }, \
	{ KEY1|KEY4,		KEY,		tag,	"a " TAG },

static Key keys[] = {
	/* modifier			key			function	argument */
	/* launchers + misc: */
	{ KEY1,				XK_Return,	spawn,		CMD(TERM)		},
	{ KEY1,				XK_p,		spawn,		CMD(DMENU)		},
	{ KEY1,				XK_w,		spawn,		CMD("luakit")	},
	{ KEY1|KEY4,		XK_q,		quit,		NULL			},
	{ KEY2,				XK_F4,		killclient,	NULL			},
	{ KEY1,				XK_f,		fullscreen,	NULL			},
	{ KEY1,				XK_Menu,	windowlist,	"interrobang alopex"},
	{ KEY1|KEY2,		XK_f,		toggle,		"floating"		},
	{ KEY1|KEY2,		XK_r,		toggle,		"root resize"	},
	{ KEY1,				XK_x,		toggle,		"place bar"		},
	{ KEY1,				XK_a,		toggle,		"visible bar"	},
	{ 0,				0x1008ff59,	spawn,		XRANDR_CMD		},
	/* tiling:
		tile modes, increase/decrease master region size,
		increment or decrement (+/-) the number of stack clients,
		select for all or one ("ttwm tiling") stack clients */
	{ KEY1,				XK_space,	tile,		"cycle"			},
	{ KEY1,				XK_b,		tile,		"bstack"		},
	{ KEY1,				XK_r,		tile,		"rstack"		},
	{ KEY1,				XK_m,		tile,		"monocle"		},
	{ KEY1,				XK_i,		tile_conf,	"increase"		},
	{ KEY1,				XK_d,		tile_conf,	"decrease"		},
	{ KEY1,				XK_equal,	tile_conf,	"+"				},
	{ KEY1,				XK_minus,	tile_conf,	"-"				},
	{ KEY1,				XK_period,	tile_conf,	"all"			},
	{ KEY1,				XK_comma,	tile_conf,	"one"			},
	/* tagging:
		flip between alternate views, set tags */
	{ KEY2,				XK_Tab,		tag,		"flip"			},
		TagKey(			XK_1,					"1"		)
		TagKey(			XK_2,					"2"		)
		TagKey(			XK_3,					"3"		)
		TagKey(			XK_4,					"4"		)
		TagKey(			XK_5,					"5"		)
		TagKey(			XK_6,					"6"		)
	/* window focus/movement:
		f=focus previous, next, or alternate  window in tag(s)
		s=swap window with previous, next, or alternate  window
		capital "Next" or "Prev" include floating windows
		+/- adjust a windows monitor number */
	{ KEY1,				XK_k,		window,		"f prev"		},
	{ KEY1,				XK_j,		window,		"f next"		},
	{ KEY1|KEY4,		XK_k,		window,		"f Prev"		},
	{ KEY1|KEY4,		XK_j,		window,		"f Next"		},
	{ KEY1,				XK_Left,	window,		"f prev"		},
	{ KEY1,				XK_Right,	window,		"f next"		},
	{ KEY1,				XK_h,		window,		"s prev"		},
	{ KEY1,				XK_l,		window,		"s next"		},
	{ KEY1,				XK_Up,		window,		"s prev"		},
	{ KEY1,				XK_Down,	window,		"s next"		},
	{ KEY1,				XK_Tab,		window,		"f alt"			},
	{ KEY1|KEY4,		XK_Tab,		window,		"s alt"			},
	{ KEY1|KEY4,		XK_equal,	window,		"+"				},
	{ KEY1|KEY4,		XK_minus,	window,		"-"				},
	{ KEY1|KEY4,		XK_space,	toggle,		"monitor focus"	},
};

static Button buttons[] = {
	/* modifier			button		function 	arg */
	{ KEY1,				1,			mouse,		"move"		},
	{ KEY1,				2,			toggle,		"floating"	},
	{ KEY1,				3,			mouse,		"resize"	},
	{ KEY1,				4,			window,		"s prev"	},
	{ KEY1,				5,			window,		"s next"	},
	{ KEY1,				6,			window,		"f prev"	},
	{ KEY1,				7,			window,		"f next"	},
};

static Rule rules[] = {
	/* name				class		tags		flags */
	/* tags/flags=0 means no change to default */
	{ NULL,				"float",	0,			FLAG_FLOATING },
	{ "float",			NULL,		0,			FLAG_FLOATING },
};

// vim: ts=4
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










































































































































































































































































































































Added doc/alopex-1.tex.





































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
\documentclass{latex2man}

\begin{Name}{1}{alopex}{Jesse McClure}{window manager}{Alopex - A Tabbed, Tiling Window Manager with Fur}

\Prog{Alopex} - A Tabbed, Tiling Window Manager with Fur

\end{Name}

\section{Synopsis}
xinit alopex \oArg{theme}

\section{Description}

\Prog{Alopex} is a dynamic tiling window manager with a container
concept inspired by i3 but implemented quite differently.  Client
windows are not statically assigned to a given container, instead,
containers each have a configurable maximum number of clients, and
clients fill each container in sequence.  Within containers, multiple
clients are displayed as tabs.

There are three container layouts: rstack, bstack, and
monocle.  Stack modes divide the screen into two sections, the master
region and the stack.  Monocle uses the full area for one container.
All layouts stack clients within containers displaying a tab for each
client in the container's title bar.  These layouts are supplimented by
per-client floating and full-screen modes.

\Prog{Alopex} uses a tag concept rather than the more common
workspace/desktop metaphor.  The default configuration, however, is
optimized for a workspace-like work flow.  This can be modified as
desired.

\section{Configuration}

Configuration is implemented via an X resources data base file which is
read on startup.  A well-commented example configuration file is
distributed with \Prog{alopex} and can be found at
\File{/usr/share/alopex/config}.  Further information on customizing and
configuring alopex can be found on the github wiki.


\section{Status Input}

A child process specified in the configuration file can be launched to
provide status input to be displayed along side the tabs in containers'
bars.  This child process should send text information to its standard
output which will then be read in by \Prog{alopex}.

Each line must contain three ampersands which delineate four text
segments.  The first two segments are always displayed in the first
container's bar: the first before the tag indicators, the second
immediately after the tag indicators.  The third segment is displayed at
the right side of the second container's bar (or the right of the first
container if there is only one visible).  The fourth segment is
displayed at the right side of the last visible container.

Plain text is printed as-is into the above-specified status bar region.
Text within curly-braces is interpreted as a special command.  These
commands can specify a foreground color, set a font, display an icon
or paint the foreground color with an icon mask.

\subsection{Status Commands}

\begin{description}
\item[\Opt{R G B A}]
	Set color with Red Green Blue and Alpha values specified as floating
	point numbers from 0 to 1
\item[\OptArg{i}{#}]
	Draw icon number # in full color
\item[\OptArg{I}{#}]
	Use icon number # as mask for the currently selected color
\item[\Opt{f}]
	Select default font
\item[\Opt{F}]
	Select bold font

\section{Author}
Copyright \copyright 2012-2014 Jesse McClure \\
License GPLv3: GNU GPL version 3 \URL{http://gnu.org/licenses/gpl.html} \\
This is free software: you are free to change and redistribute it. \\
There is NO WARRANTY, to the extent permitted by law.

Submit bug reports via github: \\
\URL{http://github/com/TrilbyWhite/alopex.git}

I would like your feedback.  If you enjoy \Prog{Alopex} see the bottom
of the site below for detauls on submitting comments: \\
\URL{http://mccluresk9.com/software.html}

Documentation added and edited collaboratively by Jesse McClure and Sam
Stuewe.  Any concerns or comments regarding documentation may be
submitted to \Email{halosghost@archlinux.info}.

\section{See Also}
The most up to date documentation can be found at
\URL{https://github.com/TrilbyWhite/alopex/wiki}

\LatexManEnd

Added doc/alopex.1.

































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
'\" t
.\" Manual page created with latex2man on Thu Mar 20 14:23:46 EDT 2014
.\" NOTE: This file is generated, DO NOT EDIT.
.de Vb
.ft CW
.nf
..
.de Ve
.ft R

.fi
..
.TH "ALOPEX" "1" "20 March 2014" "window manager " "window manager "
.SH NAME

.PP
Alopex
\- A Tabbed, Tiling Window Manager with Fur 
.PP
.SH SYNOPSIS

xinit alopex [\fItheme\fP]
.PP
.SH DESCRIPTION

.PP
Alopex
is a dynamic tiling window manager with a container 
concept inspired by i3 but implemented quite differently. Client 
windows are not statically assigned to a given container, instead, 
containers each have a configurable maximum number of clients, and 
clients fill each container in sequence. Within containers, multiple 
clients are displayed as tabs. 
.PP
There are three container layouts: rstack, bstack, and 
monocle. Stack modes divide the screen into two sections, the master 
region and the stack. Monocle uses the full area for one container. 
All layouts stack clients within containers displaying a tab for each 
client in the container\&'s title bar. These layouts are supplimented by 
per\-client floating and full\-screen modes. 
.PP
Alopex
uses a tag concept rather than the more common 
workspace/desktop metaphor. The default configuration, however, is 
optimized for a workspace\-like work flow. This can be modified as 
desired. 
.PP
.SH CONFIGURATION

.PP
Configuration is implemented via an X resources data base file which is 
read on startup. A well\-commented example configuration file is 
distributed with alopex
and can be found at 
/usr/share/alopex/config\&.
Further information on customizing and 
configuring alopex can be found on the github wiki. 
.PP
.SH STATUS INPUT

.PP
A child process specified in the configuration file can be launched to 
provide status input to be displayed along side the tabs in containers\&' 
bars. This child process should send text information to its standard 
output which will then be read in by alopex\&.
.PP
Each line must contain three ampersands which delineate four text 
segments. The first two segments are always displayed in the first 
container\&'s bar: the first before the tag indicators, the second 
immediately after the tag indicators. The third segment is displayed at 
the right side of the second container\&'s bar (or the right of the first 
container if there is only one visible). The fourth segment is 
displayed at the right side of the last visible container. 
.PP
Plain text is printed as\-is into the above\-specified status bar region. 
Text within curly\-braces is interpreted as a special command. These 
commands can specify a foreground color, set a font, display an icon 
or paint the foreground color with an icon mask. 
.PP
.SS STATUS COMMANDS
.PP
.TP
\fBR G B A\fP
 Set color with Red Green Blue and Alpha values specified as floating 
point numbers from 0 to 1 
.TP
\fBi\fP\fI#\fP
 Draw icon number # in full color 
.TP
\fBI\fP\fI#\fP
 Use icon number # as mask for the currently selected color 
.TP
\fBf\fP
 Select default font 
.TP
\fBF\fP
 Select bold font 
.PP
.SH AUTHOR

Copyright (C)2012\-2014 Jesse McClure 
.br
License GPLv3: GNU GPL version 3 \fBhttp://gnu.org/licenses/gpl.html\fP
.br
This is free software: you are free to change and redistribute it. 
.br
There is NO WARRANTY, to the extent permitted by law. 
.PP
Submit bug reports via github: 
.br
\fBhttp://github/com/TrilbyWhite/alopex.git\fP
.PP
I would like your feedback. If you enjoy Alopex
see the bottom 
of the site below for detauls on submitting comments: 
.br
\fBhttp://mccluresk9.com/software.html\fP
.PP
Documentation added and edited collaboratively by Jesse McClure and Sam 
Stuewe. Any concerns or comments regarding documentation may be 
submitted to \fBhalosghost@archlinux.info\fP\&.
.PP
.SH SEE ALSO

The most up to date documentation can be found at 
\fBhttps://github.com/TrilbyWhite/alopex/wiki\fP
.PP
.\" NOTE: This file is generated, DO NOT EDIT.

Deleted icons.h.

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
/* ICONS.H
   default icon set for alopex. Icon art contributions by github users:
     UnderCooled
	 HalosGhost
*/

#ifndef __ALOPEX_ICONS_H__
#define __ALOPEX_ICONS_H__		"ALOPEX Icons 0.9"

#define MAKE_ICON(x)	{ (sizeof(x)/sizeof(x[0])), (XPoint *) x }

static const int iconwidth = 10;
static const int iconheight = 10;

typedef struct Icon {
	int n;
	XPoint *pts;
} Icon;

/*
static const XPoint template_icon[] = {
	{0,0},	{1,0},	{2,0},	{3,0},	{4,0},	{5,0},	{6,0},	{7,0},	{8,0},	{9,0},
	{0,1},	{1,1},	{2,1},	{3,1},	{4,1},	{5,1},	{6,1},	{7,1},	{8,1},	{9,1},
	{0,2},	{1,2},	{2,2},	{3,2},	{4,2},	{5,2},	{6,2},	{7,2},	{8,2},	{9,2},
	{0,3},	{1,3},	{2,3},	{3,3},	{4,3},	{5,3},	{6,3},	{7,3},	{8,3},	{9,3},
	{0,4},	{1,4},	{2,4},	{3,4},	{4,4},	{5,4},	{6,4},	{7,4},	{8,4},	{9,4},
	{0,5},	{1,5},	{2,5},	{3,5},	{4,5},	{5,5},	{6,5},	{7,5},	{8,5},	{9,5},
	{0,6},	{1,6},	{2,6},	{3,6},	{4,6},	{5,6},	{6,6},	{7,6},	{8,6},	{9,6},
	{0,7},	{1,7},	{2,7},	{3,7},	{4,7},	{5,7},	{6,7},	{7,7},	{8,7},	{9,7},
	{0,8},	{1,8},	{2,8},	{3,8},	{4,8},	{5,8},	{6,8},	{7,8},	{8,8},	{9,8},
	{0,9},	{1,9},	{2,9},	{3,9},	{4,9},	{5,9},	{6,9},	{7,9},	{8,9},	{9,9},
};
*/

static const XPoint clock_icon[] = {
							{3,0},	{4,0},	{5,0},	{6,0},
					{2,1},									{7,1},
			{1,2},					{4,2},							{8,2},
	{0,3},							{4,3},									{9,3},
	{0,4},							{4,4},								 	{9,4},
	{0,5},							{4,5},	{5,5},	{6,5},	{7,5},			{9,5},
	{0,6},																	{9,6},
			{1,7},													{8,7},
					{2,8},									{7,8},
							{3,9},	{4,9},	{5,9},	{6,9},
};

static const XPoint cpu_icon[] = {
	{0,0},	{1,0},	{2,0},	{3,0},	{4,0},	{5,0},	{6,0},	{7,0},	{8,0},	{9,0},
	{0,1},																	{9,1},
	{0,2},					{3,2},	{4,2},	{5,2},	{6,2},					{9,2},
	{0,3},					{3,3},					{6,3},					{9,3},
	{0,4},					{3,4},			{5,4},	{6,4},					{9,4},
	{0,5},					{3,5},	{4,5},	{5,5},	{6,5},					{9,5},
	{0,6},					{3,6},	{4,6},	{5,6},	{6,6},					{9,6},
	{0,7},																	{9,7},
	{0,8},	{1,8},	{2,8},	{3,8},	{4,8},	{5,8},	{6,8},	{7,8},	{8,8},	{9,8},
	{0,9},			{2,9},			{4,9},			{6,9},			{8,9},
};

static const XPoint mem_icon[] = {
			{1,0},	{2,0},	{3,0},	{4,0},	{5,0},	{6,0},	{7,0},	{8,0},
	{0,1},																	{9,1},
	{0,2},	{1,2},			{3,2},	{4,2},	{5,2},	{6,2},			{8,2},	{9,2},
	{0,3},					{3,3},	{4,3},	{5,3},	{6,3},					{9,3},
	{0,4},	{1,4},			{3,4},	{4,4},	{5,4},	{6,4},			{8,4},	{9,4},
	{0,5},					{3,5},	{4,5},	{5,5},	{6,5},					{9,5},
	{0,6},	{1,6},			{3,6},	{4,6},	{5,6},	{6,6},			{8,6},	{9,6},
	{0,7},																	{9,7},
	{0,8},	{1,8},	{2,8},	{3,8},	{4,8},	{5,8},	{6,8},	{7,8},	{8,8},	{9,8},
	{0,9},																	{9,9},
};

static const XPoint speaker_hi_icon[] = {
									{4,0},			{6,0},
							{3,1},	{4,1},					{7,1},
					{2,2},	{3,2},	{4,2},							{8,2},
	{0,3},	{1,3},	{2,3},	{3,3},	{4,3},			{6,3},					{9,3},
	{0,4},	{1,4},	{2,4},	{3,4},	{4,4},					{7,4},			{9,4},
	{0,5},	{1,5},	{2,5},	{3,5},	{4,5},					{7,5},			{9,5},
	{0,6},	{1,6},	{2,6},	{3,6},	{4,6},			{6,6},					{9,6},
					{2,7},	{3,7},	{4,7},							{8,7},
							{3,8},	{4,8},					{7,8},
									{4,9},			{6,9},
};

static const XPoint speaker_mid_icon[] = {
									{4,0},
							{3,1},	{4,1},			{6,1},
					{2,2},	{3,2},	{4,2},					{7,2},
	{0,3},	{1,3},	{2,3},	{3,3},	{4,3},							{8,3},
	{0,4},	{1,4},	{2,4},	{3,4},	{4,4},							{8,4},
	{0,5},	{1,5},	{2,5},	{3,5},	{4,5},							{8,5},
	{0,6},	{1,6},	{2,6},	{3,6},	{4,6},							{8,6},
					{2,7},	{3,7},	{4,7},					{7,7},
							{3,8},	{4,8},			{6,8},
									{4,9},			
};

static const XPoint speaker_low_icon[] = {
									{4,0},
							{3,1},	{4,1},
					{2,2},	{3,2},	{4,2},
	{0,3},	{1,3},	{2,3},	{3,3},	{4,3},
	{0,4},	{1,4},	{2,4},	{3,4},	{4,4},
	{0,5},	{1,5},	{2,5},	{3,5},	{4,5},
	{0,6},	{1,6},	{2,6},	{3,6},	{4,6},
					{2,7},	{3,7},	{4,7},
							{3,8},	{4,8},
									{4,9},			
};

static const XPoint speaker_mute_icon[] = {
											{5,0},							{9,0},
							{3,1},			{5,1},							{9,1},
					{2,2},	{3,2},	{4,2},			{6,2},			{8,2},
	{0,3},	{1,3},	{2,3},	{3,3},	{4,3},			{6,3},			{8,3},
	{0,4},	{1,4},	{2,4},	{3,4},	{4,4},					{7,4},
	{0,5},	{1,5},	{2,5},	{3,5},	{4,5},					{7,5},	
	{0,6},	{1,6},	{2,6},	{3,6},	{4,6},			{6,6},			{8,6},
					{2,7},	{3,7},	{4,7},			{6,7},			{8,7},
							{3,8},			{5,8},							{9,8},
											{5,9},							{9,9},
};

static const XPoint wifi_full_icon[] = {
													{8,0},	
										{6,1},		{8,1},	
							{4,2},		{6,2},		{8,2},	
				{2,3},		{4,3},		{6,3},		{8,3},	
	{0,4},		{2,4},		{4,4},		{6,4},		{8,4},	
  	{0,5},		{2,5},		{4,5},		{6,5},		{8,5},	
	{0,6},		{2,6},		{4,6},		{6,6},		{8,6},	
	{0,7},		{2,7},		{4,7},		{6,7},		{8,7},	
	{0,8},		{2,8},		{4,8},		{6,8},		{8,8},	
	{0,9},		{2,9},		{4,9},		{6,9},		{8,9},	
};

static const XPoint wifi_hi_icon[] = {
													{8,0},	
													{8,1},	
										{6,2},		{8,2},	
										{6,3},		{8,3},	
							{4,4},		{6,4},		{8,4},	
  							{4,5},		{6,5},		{8,5},	
				{2,6},		{4,6},		{6,6},		{8,6},	
				{2,7},		{4,7},		{6,7},		{8,7},	
	{0,8},		{2,8},		{4,8},		{6,8},		{8,8},	
	{0,9},		{2,9},		{4,9},		{6,9},		{8,9},	
};

static const XPoint wifi_mid_icon[] = {
													{8,1},	
													{8,2},	
										{6,3},		{8,3},	
										{6,4},		{8,4},	
							{4,5},		{6,5},		{8,5},	
  							{4,6},		{6,6},		{8,6},	
				{2,7},		{4,7},		{6,7},		{8,7},	
				{2,8},		{4,8},		{6,8},		{8,8},	
				{2,9},		{4,9},		{6,9},		{8,9},	
};

static const XPoint wifi_low_icon[] = {
										{6,3},	
										{6,4},	
							{4,5},		{6,5},	
  							{4,6},		{6,6},	
				{2,7},		{4,7},		{6,7},	
				{2,8},		{4,8},		{6,8},	
				{2,9},		{4,9},		{6,9},	
};

static const XPoint wifi_off_icon[] = {
							{4,7},		{6,7},	
  							{4,8},		{6,8},	
				{2,9},		{4,9},		{6,9},	
};

static const XPoint mail_new_icon[] = {
			{1,0},	{2,0},	{3,0},	{4,0},	{5,0},	{6,0},	{7,0},	{8,0},
	{0,1},			{2,1},	{3,1},	{4,1},	{5,1},	{6,1},	{7,1},			{9,1},
	{0,2},					{3,2},	{4,2},	{5,2},	{6,2},					{9,2},
	{0,3},	{1,3},					{4,3},	{5,3},					{8,3},	{9,3},
	{0,4},	{1,4},	{2,4},									{7,4},	{8,4},	{9,4},
	{0,5},	{1,5},	{2,5},	{3,5},					{6,5},	{7,5},	{8,5},	{9,5},
	{0,6},	{1,6},	{2,6},	{3,6},	{4,6},	{5,6},	{6,6},	{7,6},	{8,6},	{9,6},
	{0,7},	{1,7},	{2,7},	{3,7},	{4,7},	{5,7},	{6,7},	{7,7},	{8,7},	{9,7},
	{0,8},	{1,8},	{2,8},	{3,8},	{4,8},	{5,8},	{6,8},	{7,8},	{8,8},	{9,8},
			{1,9},	{2,9},	{3,9},	{4,9},	{5,9},	{6,9},	{7,9},	{8,9},
};

static const XPoint mail_none_icon[] = {
			{1,0},	{2,0},	{3,0},	{4,0},	{5,0},	{6,0},	{7,0},	{8,0},
	{0,1},																	{9,1},
	{0,2},																	{9,2},
	{0,3},			{2,3},									{7,3},			{9,3},
	{0,4},					{3,4},					{6,4},					{9,4},
	{0,5},							{4,5},	{5,5},							{9,5},
	{0,6},																	{9,6},
	{0,7},																	{9,7},
	{0,8},																	{9,8},
			{1,9},	{2,9},	{3,9},	{4,9},	{5,9},	{6,9},	{7,9},	{8,9},
};

static const XPoint batt_full_icon[] = {
							{3,0},	{4,0},	{5,0},	{6,0},
	{0,1},	{1,1},	{2,1},	{3,1},					{6,1},	{7,1},	{8,1},	{9,1},
	{0,2},					{3,2},			{5,2},			{7,2},			{9,2},
	{0,3},			{2,3},			{4,3},			{6,3},					{9,3},
	{0,4},					{3,4},			{5,4},			{7,4},			{9,4},
	{0,5},			{2,5},			{4,5},			{6,5},					{9,5},
	{0,6},					{3,6},			{5,6},			{7,6},			{9,6},
	{0,7},			{2,7},			{4,7},			{6,7},					{9,7},
	{0,8},					{3,8},			{5,8},			{7,8},			{9,8},
			{1,9},	{2,9},	{3,9},	{4,9},	{5,9},	{6,9},	{7,9},	{8,9},
};

static const XPoint batt_hi_icon[] = {
							{3,0},	{4,0},	{5,0},	{6,0},
	{0,1},	{1,1},	{2,1},	{3,1},					{6,1},	{7,1},	{8,1},	{9,1},
	{0,2},													{7,2},			{9,2},
	{0,3},											{6,3},					{9,3},
	{0,4},									{5,4},			{7,4},			{9,4},
	{0,5},							{4,5},			{6,5},					{9,5},
	{0,6},					{3,6},			{5,6},			{7,6},			{9,6},
	{0,7},			{2,7},			{4,7},			{6,7},					{9,7},
	{0,8},					{3,8},			{5,8},			{7,8},			{9,8},
			{1,9},	{2,9},	{3,9},	{4,9},	{5,9},	{6,9},	{7,9},	{8,9},
};

static const XPoint batt_mid_icon[] = {
							{3,0},	{4,0},	{5,0},	{6,0},
	{0,1},	{1,1},	{2,1},	{3,1},					{6,1},	{7,1},	{8,1},	{9,1},
	{0,2},																	{9,2},
	{0,3},													{7,3},			{9,3},
	{0,4},											{6,4},					{9,4},
	{0,5},									{5,5},			{7,5},			{9,5},
	{0,6},							{4,6},			{6,6},					{9,6},
	{0,7},					{3,7},			{5,7},			{7,7},			{9,7},
	{0,8},			{2,8},			{4,8},			{6,8},					{9,8},
			{1,9},	{2,9},	{3,9},	{4,9},	{5,9},	{6,9},	{7,9},	{8,9},
};

static const XPoint batt_low_icon[] = {
							{3,0},	{4,0},	{5,0},	{6,0},
	{0,1},	{1,1},	{2,1},	{3,1},					{6,1},	{7,1},	{8,1},	{9,1},
	{0,2},																	{9,2},
	{0,3},																	{9,3},
	{0,4},																	{9,4},
	{0,5},													{7,5},			{9,5},
	{0,6},											{6,6},					{9,6},
	{0,7},									{5,7},			{7,7},			{9,7},
	{0,8},							{4,8},			{6,8},					{9,8},
			{1,9},	{2,9},	{3,9},	{4,9},	{5,9},	{6,9},	{7,9},	{8,9},
};

static const XPoint batt_zero_icon[] = {
							{3,0},	{4,0},	{5,0},	{6,0},
	{0,1},	{1,1},	{2,1},	{3,1},					{6,1},	{7,1},	{8,1},	{9,1},
	{0,2},																	{9,2},
	{0,3},																	{9,3},
	{0,4},																	{9,4},
	{0,5},																	{9,5},
	{0,6},																	{9,6},
	{0,7},																	{9,7},
	{0,8},																	{9,8},
			{1,9},	{2,9},	{3,9},	{4,9},	{5,9},	{6,9},	{7,9},	{8,9},
};

static const XPoint batt_charge_icon[] = {
													{6,0},	{7,0},
											{5,1},	{6,1},
									{4,2},	{5,2},	
							{3,3},	{4,3},		
					{2,4},	{3,4},	{4,4},	{5,4},	{6,4},	{7,4},	{8,4},
			{1,5},	{2,5},	{3,5},	{4,5},	{5,5},	{6,5},	{7,5},
											{5,6},	{6,6},
									{4,7},	{5,7},
							{3,8},	{4,8},
					{2,9},	{3,9},
};

static const XPoint arch_icon[] = {
									{4,0},	{5,0},
									{4,1},	{5,1},
							{3,2},	{4,2},	{5,2},	{6,2},
							{3,3},	{4,3},	{5,3},	{6,3},
					{2,4},	{3,4},	{4,4},	{5,4},	{6,4},	{7,4},
					{2,5},	{3,5},					{6,5},	{7,5},
			{1,6},	{2,6},	{3,6},					{6,6},	{7,6},	{8,6},
			{1,7},	{2,7},	{3,7},					{6,7},	{7,7},	{8,7},
	{0,8},	{1,8},	{2,8},									{7,8},	{8,8},	{9,8},
	{0,9},	{1,9},													{8,9},	{9,9},
};

static const XPoint app_term[] = { 
   {0,0},   {1,0},   {2,0},   {3,0},   {4,0},   {5,0},   {6,0},   {7,0},   {8,0},   {9,0},
   {0,1},   {1,1},   {2,1},   {3,1},   {4,1},   {5,1},   {6,1},   {7,1},   {8,1},   {9,1},
   {0,2},                                                                           {9,2},
   {0,3},            {2,3},                                                         {9,3},
   {0,4},            {2,4},   {3,4},                                                {9,4},
   {0,5},                     {3,5},                                                {9,5},
   {0,6},            {2,6},   {3,6},                                                {9,6},
   {0,7},            {2,7},                     {5,7},   {6,7},   {7,7},            {9,7},
   {0,8},                                                                           {9,8},
   {0,9},   {1,9},   {2,9},   {3,9},   {4,9},   {5,9},   {6,9},   {7,9},   {8,9},   {9,9},
};

static const XPoint app_web[] = { 
                     {2,0},   {3,0},   {4,0},   {5,0},            {7,0},
            {1,1},                     {4,1},   {5,1},                     {8,1},
   {0,2},   {1,2},                                                         {8,2},   {9,2},
   {0,3},                              {4,3},   {5,3},                              {9,3},
   {0,4},   {1,4},                     {4,4},   {5,4},                     {8,4},   {9,4},
            {1,5},                     {4,5},   {5,5},                     {8,5},
                     {2,6},            {4,6},   {5,6},   {6,6},   {7,6},
                                       {4,7},   {5,7},
                                       {4,8},   {5,8},
                                       {4,9},   {5,9},
};

static const XPoint app_stats[] = { 
   {0,0},
   {0,1},
   {0,2},                     {3,2},
   {0,3},            {2,3},            {4,3},
   {0,4},            {2,4},                     {4,4},
   {0,5},   {1,5},                              {5,5},
   {0,6},   {1,6},                                    {5,6},   {6,6},
   {0,7},                                                         {7,7},
   {0,8},                                                                  {8,8},   {9,8},
   {0,9},   {1,9},   {2,9},   {3,9},   {4,9},   {5,9},   {6,9},   {7,9},   {8,9},   {9,9},
};

static const XPoint app_docs[] = { 
            {1,0},   {2,0},   {3,0},   {4,0},   {5,0},
            {1,1},                                       {6,1},
            {1,2},                                                {7,2},
            {1,3},            {3,3},   {4,3},   {5,3},                     {8,3},
            {1,4},                                                         {8,4},
            {1,5},            {3,5},   {4,5},   {5,5},   {6,5},            {8,5},
            {1,6},                                                         {8,6},
            {1,7},            {3,7},   {4,7},   {5,7},   {6,7},            {8,7},
            {1,8},                                                         {8,8},
            {1,9},   {2,9},   {3,9},   {4,9},   {5,9},   {6,9},   {7,9},   {8,9},
};

static const XPoint app_music[] = { 
                              {3,0},   {4,0},   {5,0},   {6,0},   {7,0},   {8,0},   {9,0},
                              {3,1},   {4,1},   {5,1},   {6,1},   {7,1},   {8,1},   {9,1},
                              {3,2},                                                {9,2},
                              {3,3},                                                {9,3},
                              {3,4},                                                {9,4},
            {1,5},   {2,5},   {3,5},                                                {9,5},
   {0,6},   {1,6},   {2,6},   {3,6},                              {7,6},   {8,6},   {9,6},
   {0,7},   {1,7},   {2,7},   {3,7},                     {6,7},   {7,7},   {8,7},   {9,7},
            {1,8},   {2,8},                              {6,8},   {7,8},   {8,8},   {9,8},
                                                                  {7,9},   {8,9},
};

static const XPoint app_video[] = { 
   {0,0},            {2,0},                                       {7,0},            {9,0},
   {0,1},   {1,1},   {2,1},                                       {7,1},   {8,1},   {9,1},
   {0,2},            {2,2},   {3,2},   {4,2},   {5,2},   {6,2},   {7,2},            {9,2},
   {0,3},   {1,3},   {2,3},                                       {7,3},   {8,3},   {9,3},
   {0,4},            {2,4},                                       {7,4},            {9,4},
   {0,5},   {1,5},   {2,5},                                       {7,5},   {8,5},   {9,5},
   {0,6},            {2,6},                                       {7,6},            {9,6},
   {0,7},   {1,7},   {2,7},   {3,7},   {4,7},   {5,7},   {6,7},   {7,7},   {8,7},   {9,7},
   {0,8},            {2,8},                                       {7,8},            {9,8},
   {0,9},   {1,9},   {2,9},                                       {7,9},   {8,9},   {9,9},
};

static const XPoint app_games[] = {
                     {2,0},   {3,0},   {4,0},   {5,0},   {6,0},   {7,0},
                     {2,1},                                       {7,1},
   {0,2},   {1,2},   {2,2},                                       {7,2},   {8,2},   {9,2},
   {0,3},                              {4,3},                                       {9,3},
   {0,4},                              {4,4},   {5,4},                              {9,4},
   {0,5},                              {4,5},   {5,5},                              {9,5},
   {0,6},                              {4,6},                                       {9,6},
   {0,7},   {1,7},   {2,7},                                       {7,7},   {8,7},   {9,7},
                     {2,8},                                       {7,8},
                     {2,9},   {3,9},   {4,9},   {5,9},   {6,9},   {7,9},
};

static const XPoint app_images[] = { 
   {0,0},   {1,0},   {2,0},   {3,0},   {4,0},   {5,0},   {6,0},   {7,0},   {8,0},   {9,0},
   {0,1},                                                                           {9,1},
   {0,2},                                                                           {9,2},
   {0,3},                                                                           {9,3},
   {0,4},                                                                           {9,4},
   {0,5},            {2,5},   {3,5},   {4,5},                                       {9,5},
   {0,6},   {1,6},   {2,6},   {3,6},   {4,6},   {5,6},                     {8,6},   {9,6},
   {0,7},   {1,7},   {2,7},   {3,7},   {4,7},   {5,7},   {6,7},   {7,7},   {8,7},   {9,7},
   {0,8},   {1,8},   {2,8},   {3,8},   {4,8},   {5,8},   {6,8},   {7,8},   {8,8},   {9,8},
   {0,9},   {1,9},   {2,9},   {3,9},   {4,9},   {5,9},   {6,9},   {7,9},   {8,9},   {9,9},
};

static const Icon icons[] = {
	[0]		= MAKE_ICON(clock_icon),
	[1]		= MAKE_ICON(cpu_icon),
	[2]		= MAKE_ICON(mem_icon),
	[3]		= MAKE_ICON(speaker_hi_icon),
	[4]		= MAKE_ICON(speaker_mid_icon),
	[5]		= MAKE_ICON(speaker_low_icon),
	[6]		= MAKE_ICON(speaker_mute_icon),
	[7]		= MAKE_ICON(wifi_full_icon),
	[8]		= MAKE_ICON(wifi_hi_icon),
	[9]		= MAKE_ICON(wifi_mid_icon),
	[10]	= MAKE_ICON(wifi_low_icon),
	[11]	= MAKE_ICON(wifi_off_icon),
	[12]	= MAKE_ICON(mail_new_icon),
	[13]	= MAKE_ICON(mail_none_icon),
	[14]	= MAKE_ICON(batt_full_icon),
	[15]	= MAKE_ICON(batt_hi_icon),
	[16]	= MAKE_ICON(batt_mid_icon),
	[17]	= MAKE_ICON(batt_low_icon),
	[18]	= MAKE_ICON(batt_zero_icon),
	[19]	= MAKE_ICON(batt_charge_icon),
	[20]	= MAKE_ICON(arch_icon),
	[21]	= MAKE_ICON(app_term),
	[22]	= MAKE_ICON(app_web),
	[23]	= MAKE_ICON(app_stats),
	[24]	= MAKE_ICON(app_docs),
	[25]	= MAKE_ICON(app_music),
	[26]	= MAKE_ICON(app_video),
	[27]	= MAKE_ICON(app_games),
	[28]	= MAKE_ICON(app_images),
};

// vim: ts=4
#endif /* __ALOPEX_ICONS_H__ */


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<








































































































































































































































































































































































































































































































































































































































































































































































































































































































Added share/config.







































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
!! Alopex resource database
!! By: Jesse McClure (c) 2014
!! License: CC-BY-SA
!!   http://creativecommons.org/licenses/by-sa/4.0/

! including a specific theme file (rather than all three) will
!  slghtly reduce memory use.  By default all three are included
#include "/usr/share/alopex/themes"

!----- Theme name -----!
! Used to apply theme specific settings, defaults to icecap
! Thi can be overriden by passing a theme name on the command line
Alopex.Theme:           icecap
! Other config settings can be set differently for different themes.
! For example the following three entries could all be sepcified:
!    *.Tiling.Split:           0
!    icecap.Tiling.Split:      10
!    tundra.Tiling.Split:      -10
! This would allow the split to be set on a per theme basis, so simply
!   changing the them name here, or on the command line, would load a
!   different subset of settings.  As can be read in the xrdb docs,
!   a matching implicitly named specifier takes precident over wildcards.

!----- Bar -----!
! A program or script that sends status strings to it's stdout
*.Bar.StatInput:			/path/to/stat
! Font info
*.Bar.Font:					/usr/share/fonts/TTF/DroidSansMono.ttf
*.Bar.BoldFont:			/usr/share/fonts/TTF/DroidSans-Bold.ttf
*.Bar.FontSize:			14
! PNG file with 10x10 grid of icons 1-100
*.Bar.Icons:				/path/to/icons.png
! Height of bars: "default" bases height on font extents
*.Bar.Height:           default
! Options: visible/hidden top/bottom
*.Bar.Options:				visible top

!----- Tiling -----!
! PNG for wallpaper
*.Tiling.Background:		/path/to/background.png
! Pixel count for how much larger the first container is than others
*.Tiling.Split:			0
! Padding between tiles (e.g. "useless gap")
*.Tiling.Padding:			0
! Number of clients per container, there will always be one more
!  container than specified here to hold any/all overflow
*.Tiling.Containers:		1 3 3
! rstack bstack or monocle
*.Tiling.Mode:				rstack
! pixels for the top bottom left and right of monitor that will not
!  be used: space can be reserved for external bars/trays/docks
*.Tiling.Margin:			0 0 0 0

!----- Tags -----!
! icon-tex text-icon icon text to specify what shows in tags
*.Tags.Mode:            icon-text
! specify a single '-' for a name to not show a name for tag
*.Tags.Names:				one two three four five
! specify a -1 for a tag to now show an icon
*.Tags.Icons:				1 2 3 4 5
! space between tags
*.Tags.Padding:			5

!----- Clients -----!
*.Clients.FollowMouse:	false
! top bottom above or below
*.Clients.Attach:			top

!----- Rules -----!
! Each rule needs either a name, class, or both plus a specification
!  for flags (float fullscreen) and/or tags (list for multiple)
*.Rule.00.Name:			Float
*.Rule.00.Flags:			float
*.Rule.01.Class:			Float
*.Rule.01.Flags:			float
*.Rule.02.Class:			Firefox
*.Rule.02.Tags:			2

!----- Binds -----!
! Each key can have up to five bindings using different modifiers
! Each key is numbered from 00-99
! See "Commands" description in a man page or github wiki for
!  a description of the command language used for bindings
!  NOTE: the wiki is currently outdated
! Modifier definitions
*.Bind.Mod.First:			Super
*.Bind.Mod.Second:		Super Alt
*.Bind.Mod.Third:			Super Shift
*.Bind.Mod.Fourth:		Super Control
*.Bind.Mod.Fifth:			Alt
! General bindings
*.Bind.00.Key:			q
*.Bind.00.Third:		quit
*.Bind.01.Key:			Return
*.Bind.01.First:		exec urxvt
*.Bind.02.Key:			w
*.Bind.02.First:		exec firefox
*.Bind.03.Key:			F4
*.Bind.03.Fifth:		kill
! Tiling mode
*.Bind.50.Key:			space
*.Bind.50.First:		layout
*.Bind.50.Second:		layout default
*.Bind.50.Third:		layout monocle
! Floating / Fullscren:
*.Bind.51.Key:			f
*.Bind.51.First:		float
*.Bind.51.Third:		fullscreen
! Focus / Move
! focus (top|bottom|up|down)
! move (top|bottom|up|down)
! win # move (above|below)
*.Bind.60.Key:			Tab
*.Bind.60.First:		focus previous
*.Bind.60.Third:		focus floater
*.Bind.60.Fifth:		view
*.Bind.61.Key:			h
*.Bind.61.First:		focus top
*.Bind.61.Third:		move top
*.Bind.62.Key:			j
*.Bind.62.First:		focus down
*.Bind.62.Third:		move down
*.Bind.63.Key:			k
*.Bind.63.First:		focus up
*.Bind.63.Third:		move up
*.Bind.64.Key:			l
*.Bind.64.First:		focus bottom
*.Bind.64.Third:		move bottom
! Modify Settings
! bar (top|bottom|show|hide|toggle) [all]
*.Bind.70.Key:			x
*.Bind.70.First:		bar toggle
*.Bind.70.Second:		bar show all
*.Bind.70.Third:		bar toggle all
*.Bind.70.Fourth:		bar hide all
! (split|gap|number) (increase|decrease|set|reset) [#]
*.Bind.71.Key:			i
*.Bind.71.First:		split increase 1
*.Bind.71.Second:		gap increase 1
*.Bind.71.Third:		number increase 1
*.Bind.72.Key:			d
*.Bind.72.First:		split decrease 1
*.Bind.72.Second:		gap decrease 1
*.Bind.72.Third:		number decrease 1
*.Bind.73.Key:			r
*.Bind.73.First:		split reset
*.Bind.73.Second:		gap reset
*.Bind.73.Third:		number reset
! Tag bindings
! [win [#]] tag (toggle|set|add|remove) #
*.Bind.81.Key:			1
*.Bind.81.First:		tag set 1
*.Bind.81.Second:		tag toggle 1
*.Bind.81.Third:		win tag set 1
*.Bind.81.Fourth:		win tag toggle 1
*.Bind.82.Key:			2
*.Bind.82.First:		tag set 2
*.Bind.82.Second:		tag toggle 2
*.Bind.82.Third:		win tag set 2
*.Bind.82.Fourth:		win tag toggle 2
*.Bind.83.Key:			3
*.Bind.83.First:		tag set 3
*.Bind.83.Second:		tag toggle 3
*.Bind.83.Third:		win tag set 3
*.Bind.83.Fourth:		win tag toggle 3
*.Bind.84.Key:			4
*.Bind.84.First:		tag set 4
*.Bind.84.Second:		tag toggle 4
*.Bind.84.Third:		win tag set 4
*.Bind.84.Fourth:		win tag toggle 4
! Window marks:
*.Bind.92.Key:			F2
*.Bind.92.First:		w2f
*.Bind.92.Second:		z2
*.Bind.93.Key:			F3
*.Bind.93.First:		win 3f
*.Bind.93.Second:		z3

!! vim: ft=xdefaults

Added share/flats.

















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
!! Alopex resource database: theme flats
!! By: Jesse McClure (c) 2014
!! License: CC-BY-SA

flats.Tab.Offset:					0.00 0.00 0.00 2.00 0.0
flats.Tab.Background:			0.08 0.08 0.08 0.00 0.0
flats.Tab.Border:					0.00 0.20 1.00 0.00 0.5
flats.Tab.Text:					0.20 0.40 0.80 1.00 -10
flats.TabFocus.Background:		0.14 0.14 0.14 0.00 0.0
flats.TabFocus.Border:			0.60 0.90 1.00 0.00 0.5
flats.TabFocus.Text:				0.90 0.95 1.00 1.00 -10
flats.TabTop.Background:		0.14 0.14 0.14 0.00 0.0
flats.TabTop.Border:				0.00 0.40 1.00 0.00 0.5
flats.TabTop.Text:				0.35 0.75 1.00 1.00 -10
flats.Status.Offset:				0.00 0.00 0.00 0.00 0.0
flats.Status.Background:		0.14 0.14 0.14 0.00 0.0
flats.Status.Border:				0.60 0.90 1.00 0.00 0.0
flats.Status.Text:				0.80 0.80 0.80 1.00 0.0
flats.Tag.Occupied:				0.60 0.90 1.00 1.00 0.0
flats.Tag.View:					0.90 0.95 1.00 1.00 0.0
flats.Tag.Alt:						0.35 0.75 1.00 1.00 0.0
flats.Tag.Both:					0.60 1.00 0.60 1.00 0.0

!! vim: ft=xdefaults

Added share/icecap.

















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
!! Alopex resource database: theme icecap
!! By: Jesse McClure (c) 2014
!! License: CC-BY-SA

icecap.Tab.Offset:				2.00 1.00 -4.0 10.0 6.0
icecap.Tab.Background:			0.04 0.04 0.04 0.60 0.0
icecap.Tab.Border:				0.00 0.20 1.00 0.45 0.8
icecap.Tab.Text:					0.25 0.45 1.00 0.40 0.5
icecap.TabFocus.Background:	0.14 0.14 0.14 1.00 0.0
icecap.TabFocus.Border:			0.60 0.90 1.00 0.95 1.2
icecap.TabFocus.Text:			0.90 0.95 1.00 0.90 -10
icecap.TabTop.Background:		0.14 0.14 0.14 1.00 0.0
icecap.TabTop.Border:			0.00 0.40 1.00 0.80 1.0
icecap.TabTop.Text:				0.25 0.65 1.00 0.70 0.5
icecap.Status.Offset:			1.00 2.00 -2.0 -4.0 5.0
icecap.Status.Background:		0.14 0.14 0.14 0.40 0.0
icecap.Status.Border:			1.00 1.00 1.00 0.60 1.0
icecap.Status.Text:				0.80 0.80 0.80 1.00 0.0
icecap.Tag.Occupied:				0.00 0.00 1.00 1.00 0.0
icecap.Tag.View:					1.00 1.00 1.00 1.00 0.0
icecap.Tag.Alt:					0.80 0.00 0.00 1.00 0.0
icecap.Tag.Both:					0.80 0.00 0.80 1.00 0.0

!! vim: ft=xdefaults

Added share/polar.

















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
!! Alopex resource database: theme polar
!! By: Jesse McClure (c) 2014
!! License: CC-BY-SA

polar.Tab.Offset:					1.50 1.00 -3.0 2.00 3.0
polar.Tab.Background:			0.06 0.06 0.06 1.00 0.0
polar.Tab.Border:					0.00 0.20 1.00 0.45 0.8
polar.Tab.Text:					0.25 0.45 1.00 0.40 0.5
polar.TabFocus.Background:		0.14 0.14 0.14 1.00 0.0
polar.TabFocus.Border:			0.60 0.90 1.00 0.95 1.2
polar.TabFocus.Text:				0.90 0.95 1.00 0.90 -10
polar.TabTop.Background:		0.14 0.14 0.14 1.00 0.0
polar.TabTop.Border:				0.00 0.40 1.00 0.80 1.0
polar.TabTop.Text:				0.25 0.65 1.00 0.70 0.5
polar.Status.Offset:				1.50 -2.0 -3.0 1.00 3.0
polar.Status.Background:		0.14 0.14 0.14 1.00 0.0
polar.Status.Border:				1.00 1.00 1.00 0.60 1.0
polar.Status.Text:				0.80 0.80 0.80 1.00 0.0
polar.Tag.Occupied:				0.00 0.00 1.00 1.00 0.0
polar.Tag.View:					1.00 1.00 1.00 1.00 0.0
polar.Tag.Alt:						0.80 0.00 0.00 1.00 0.0
polar.Tag.Both:					0.80 0.00 0.80 1.00 0.0

!! vim: ft=xdefaults

Added share/taiga.





















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
!! Alopex resource database: theme taiga
!! By: Jesse McClure (c) 2014
!! License: CC-BY-SA

! TODO modify to taiga - right now this is mostly just a copy of icecap

taiga.Tab.Offset:					2.00 2.00 -4.0 -4.0 0.0
taiga.Tab.Background:			0.20 0.60 0.30 0.60 0.0
taiga.Tab.Border:					0.35 0.75 0.45 0.60 0.8
taiga.Tab.Text:					0.90 0.90 0.50 0.40 0.5
taiga.TabFocus.Background:		0.00 0.50 0.10 1.00 0.0
taiga.TabFocus.Border:			0.45 1.00 0.65 0.95 1.2
taiga.TabFocus.Text:				0.90 1.00 0.70 0.90 -10
taiga.TabTop.Background:		0.00 0.50 0.10 1.00 0.0
taiga.TabTop.Border:				0.10 0.85 0.60 0.80 1.0
taiga.TabTop.Text:				0.75 1.00 0.85 0.70 0.5
taiga.Status.Offset:				2.00 2.00 -4.0 -4.0 0.0
taiga.Status.Background:		0.10 0.55 0.20 0.40 0.0
taiga.Status.Border:				0.70 1.00 0.60 0.60 1.0
taiga.Status.Text:				0.60 0.80 0.60 1.00 0.0
taiga.Tag.Occupied:				0.40 1.00 0.40 1.00 0.0
taiga.Tag.View:					0.90 1.00 0.90 1.00 0.0
taiga.Tag.Alt:						0.80 0.80 0.00 1.00 0.0
taiga.Tag.Both:					0.60 1.00 0.00 1.00 0.0

!! vim: ft=xdefaults

Added share/themes.





















>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
!! Alopex resource database: themes
!! By: Jesse McClure (c) 2014
!! License: CC-BY-SA

#include "/usr/share/alopex/icecap"
#include "/usr/share/alopex/polar"
#include "/usr/share/alopex/tundra"
#include "/usr/share/alopex/taiga"

!! vim: ft=xdefaults

Added share/tundra.

















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
!! Alopex resource database: theme tundra
!! By: Jesse McClure (c) 2014
!! License: CC-BY-SA

tundra.Tab.Offset:				1.00 1.00 -2.0 2.00 3.0
tundra.Tab.Background:			0.08 0.08 0.08 1.00 0.0
tundra.Tab.Border:				0.40 0.40 0.34 1.00 0.8
tundra.Tab.Text:					0.40 0.40 0.34 1.00 0.5
tundra.TabFocus.Background:	0.14 0.14 0.14 1.00 0.0
tundra.TabFocus.Border:			0.82 0.68 0.44 1.00 1.2
tundra.TabFocus.Text:			0.94 0.80 0.68 0.90 -10
tundra.TabTop.Background:		0.14 0.14 0.14 1.00 0.0
tundra.TabTop.Border:			0.80 0.53 0.28 1.00 1.0
tundra.TabTop.Text:				0.40 0.40 0.34 1.00 0.5
tundra.Status.Offset:			0.00 0.00 0.00 0.00 0.0
tundra.Status.Background:		0.12 0.10 0.08 1.00 0.0
tundra.Status.Border:			0.12 0.10 0.08 1.00 0.0
tundra.Status.Text:				0.94 0.80 0.68 1.00 0.0
tundra.Tag.Occupied:				0.40 0.40 0.34 1.00 0.0
tundra.Tag.View:					0.86 0.80 0.50 1.00 0.0
tundra.Tag.Alt:					1.00 0.15 0.00 1.00 0.0
tundra.Tag.Both:					0.94 0.50 0.25 1.00 0.0

!! vim: ft=xdefaults

Added src/actions.c.









































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

#include "alopex.h"
#include "actions.h"

extern Bool tile_check(Monitor *, Client *);
extern int send_message(Client *, int, int);


int command(const char *cmd) {
	//if (cmd[0] == '!') return spawn(cmd+1);
	char *tok, *sptr, *str;
	str = strdup(cmd);
	for (tok = strtok_r(str, ";", &sptr); tok;
			tok = strtok_r(NULL, ";", &sptr))
		word(tok);
	free(str);
	return 0;
}

void conftile(Client *t, const char **arg) {
	if (!m->focus || !arg[0]) return;
	int n, *opt = NULL, r;
	switch (arg[0][0]) {
		case 'n': opt = &m->focus->n; r = m->focus->nn; break;
		case 's': opt = &m->split; r = conf.split; break;
		case 'g': opt = &m->gap; r = conf.gap; break;
	}
	if (!opt || !arg[1]) return;
	if (arg[2]) n = atoi(arg[2]);
	else n = 1;
	switch (arg[1][0]) {
		case 'i': *opt += n; break;
		case 'd': *opt -= n; break;
		case 'r': *opt = r; break;
		case 's': *opt = n; break;
	}
}

void floater(Client *t, const char **arg) {
	if (!t && !(t=winmarks[1])) return;
	if (t->flags & WIN_FLOAT) t->flags &= ~WIN_FULL;
	else t->flags |= WIN_FLOAT;
}

void fullscreen(Client *t, const char **arg) {
	if (!t && !(t=winmarks[1])) return;
	if (t->flags & WIN_FULL_TEST) t->flags &= ~WIN_FULL;
	else t->flags |= WIN_FULL;
}

void focus(Client *t, const char **arg) {
	if (t) {
		winmarks[0] = winmarks[1];
		winmarks[1] = t;
		return;
	}
	Container *C;
	Client *c, *a, *b = NULL;
	if (!(c=winmarks[1])) return;
	if (strncasecmp(arg[0],"flo",3)==0) { /* focus floating */
		for (a = winmarks[1]->next; a; a = a->next)
			if (a->flags & WIN_FLOAT) break;
		if (!a) for (a = clients; a; a = a->next)
			if (a->flags & WIN_FLOAT) break;
		if (!a) return;
		winmarks[0] = winmarks[1];
		winmarks[1] = a;
	}
	else if (strncasecmp(arg[0],"top",3)==0) { /* focus top */
		for (C = m->container; C && C->next; C = C->next) {
			if (C->next == m->focus) {
				winmarks[0] = winmarks[1];
				winmarks[1] = C->top;
			}
		}
	}
	else if (strncasecmp(arg[0],"dow",3)==0) { /* focus down */
		for (a = c->next; a; a = a->next)
			if (tile_check(m, a)) break;
		if (a) {
			winmarks[0] = winmarks[1];
			winmarks[1] = a;
		}
	}
	else if (strncasecmp(arg[0],"up",2)==0) { /* focus up */
		for (a = clients; a && a != c; a = a->next)
			if (tile_check(m, a)) b = a;
		if (b) {
			winmarks[0] = winmarks[1];
			winmarks[1] = b;
		}
	}
	else if (strncasecmp(arg[0],"bot",3)==0) { /* focus bottom */
		if (m->focus->next && m->focus->next->top) {
			winmarks[0] = winmarks[1];
			winmarks[1] = m->focus->next->top;
		}
	}
	else if (strncasecmp(arg[0],"pre",3)==0) { /* focus previous */
		if (winmarks[0] && (winmarks[0]->tags & m->tags)) {
			/* focus previous */
			a = winmarks[0];
			winmarks[0] = winmarks[1];
			winmarks[1] = a;
		}
		else { /* focus first container, or next container ... */
			C = m->container;
			if (C->top == winmarks[1]) C = C->next;
			if (C->top)
				a = C->top;
			else /* ... only one container -> focus another client */
				for (a = clients; a; a = a->next)
					if (a != winmarks[1] && tile_check(m, a)) break;
			if (a) {
				winmarks[0] = winmarks[1];
				winmarks[1] = a;
			}
		}
	}
}

void killclient(Client *c, const char **arg) {
	if (!c && !(c=winmarks[1])) return;
	send_message(c, WM_PROTOCOLS, WM_DELETE_WINDOW);
}

void layout(Client *c, const char **arg) {
	if (!arg[0]) { if ( (++m->mode) == LAST_MODE ) m->mode = 0; }
	else if (strncasecmp(arg[0],"rst",3)==0) m->mode = RSTACK;
	else if (strncasecmp(arg[0],"bst",3)==0) m->mode = BSTACK;
	else if (strncasecmp(arg[0],"mon",3)==0) m->mode = MONOCLE;
	else if (strncasecmp(arg[0],"def",3)==0) m->mode = conf.mode;
}

void mark_client(Client *t, const char **arg) {
	int n = atoi(arg[0]);
	if (!(t=winmarks[1])) return;
	if (n > 1 && n < 10) winmarks[n] = t;
	else if (n == 1) { winmarks[0] = winmarks[1]; winmarks[1] = t; }
}

void mod_bar(Client *t, const char **arg) {
	if (!arg[0]) return;
	Container *C;
	Bar *b;
	if (!m->focus || !(b=m->focus->bar)) return;
	int all = 0;
	if (arg[1] && strncasecmp(arg[1],"all",3)==0) all = 1;
	if (all) {
		if (strncasecmp(arg[0],"sho",3)==0)
			for (C = m->container; C; C = C->next)
				C->bar->opts &= ~BAR_HIDE;
		else if (strncasecmp(arg[0],"hid",3)==0)
			for (C = m->container; C; C = C->next)
				C->bar->opts |= BAR_HIDE;
		else if (strncasecmp(arg[0],"tog",3)==0)
			for (C = m->container; C; C = C->next)
				C->bar->opts ^= BAR_HIDE;
		else if (strncasecmp(arg[0],"top",3)==0)
			for (C = m->container; C; C = C->next)
				C->bar->opts &= ~BAR_BOTTOM;
		else if (strncasecmp(arg[0],"bot",3)==0)
			for (C = m->container; C; C = C->next)
				C->bar->opts |= BAR_BOTTOM;
	}
	else {
		if (strncasecmp(arg[0],"sho",3)==0) b->opts &= ~BAR_HIDE;
		else if (strncasecmp(arg[0],"hid",3)==0) b->opts |= BAR_HIDE;
		else if (strncasecmp(arg[0],"tog",3)==0) b->opts ^= BAR_HIDE;
		else if (strncasecmp(arg[0],"top",3)==0) b->opts &= ~BAR_BOTTOM;
		else if (strncasecmp(arg[0],"bot",3)==0) b->opts |= BAR_BOTTOM;
	}
}

void monitor(Client *t, const char **arg) {
//	int n1, n2, n3, n4;
//	if (*s == 'm') { /* margins */
//		if (s[1] == 'r')
//			m->margin = conf.margin;
//		else {
//			sscanf(s,"m%d,%d,%d,%d", &n1, &n2, &n3, &n4);
//			m->margin.top = n1;
//			m->margin.bottom = n2;
//			m->margin.left = n3;
//			m->margin.right = n4;
//		}
//	}
//	else if (*s == 's') { /* swap tags */
//		sscanf(s,"s%d,%d", &n1, &n2);
//		Monitor *M, *a = NULL, *b = NULL;
//		for (M = mons, n3 = 1; M; n3++, M = M->next) {
//			if (n1 == n3) a = M;
//			else if (n2 == n3) b = M;
//		}
//		if (a && b) {
//			n4 = a->tags;
//			a->tags = b->tags;
//			b->tags = n4;
//		}
//	}
//	else if (*s == 'c') { /* cycle through monitors */
//		m = m->next;
//		if (!m) m = mons;
//	}
//	else { /* focus another monitor */
//		n1 = atoi(s);
//		Monitor *M;
//		for (M = mons; n1 > 0 && M; n1--, M = M->next) m = M;
//	}
//	return 0;
}

void move(Client *t, const char **arg) {
	Client *c, *a, *b;
	if (!(c=winmarks[1]) || !arg || !arg[0]) return;
	if (t) { /* move focused window relative to t */
		if (!(m->focus && m->focus->top) || c == t) return;
		switch (arg[0][0]) {
			case 'a': pull_client(c); push_client(c, t); break;
			case 'b': pull_client(c); push_client(c, t->next); break;
		}
		return;
	}
	/* else move focused in direction */
	if (strncasecmp(arg[0],"top",3)==0) {
		pull_client(c); push_client(c, clients);
	}
	else if (strncasecmp(arg[0],"dow",3)==0) {
		for (a = c->next; a; a = a->next)
			if (tile_check(m, a)) break;
		if (a) for (a = a->next; a; a = a->next)
			if (tile_check(m, a)) break;
		pull_client(c); push_client(c, a);
	}
	else if (strncasecmp(arg[0],"up",3)==0) {
		for (a = clients; a && a != c; a = a->next)
			if (tile_check(m, a)) b = a;
		if (b) { pull_client(c); push_client(c, b); }
	}
	else if (strncasecmp(arg[0],"up",3)==0) {
		pull_client(c); push_client(c, NULL);
	}
}

void pull_client(Client *c) {
	Client *cur, *pre = NULL;
	for (cur = clients; cur != c; cur = cur->next) pre = cur;
	if (pre) pre->next = cur->next;
	else clients = cur->next;
	cur->next = NULL;
}

void push_client(Client *insert, Client *before) {
	Client *cur, *pre = NULL;
	for (cur = clients; cur != before; cur = cur->next) pre = cur;
	if (pre) pre->next = insert;
	else clients = insert;
	insert->next = cur;
}

void spawn(Client *t, const char **arg) {
	if (!arg || !arg[0]) return;
	if (!fork()) {
		setsid();
		close(ConnectionNumber(dpy));
		if (conf.stat) fclose(conf.stat);
		if (conf.statfd) close(conf.statfd);
		execvp(arg[0], (char * const *) arg);
	}
}

void tag(Client *t, const char **arg) {
	if (!arg || !arg[0] || !arg[1]) return;
	int tag = atoi(arg[1]);
	if (!tag || tag > 15) return;
	tag = (1<<(tag-1));
	int *n;
	if (!t) n = &m->tags;
	else n = &t->tags;
	switch (arg[0][0]) { /* set toggle add remove */
		case 's': *n = (*n & 0xFFFF0000) | tag; break;
		case 't': *n ^= tag; break;
		case 'a': *n |= tag; break;
		case 'r': *n &= ~tag; break;
	}
}

void word(const char *word) {
	char **arg = NULL, *tok, *sptr, *tmp;
	const char **parg;
	int i, n;
	tmp = strdup(word);
	tok = strtok_r(tmp, " ", &sptr);
	for (i = 0; tok; i++) {
		arg = realloc(arg, (i+1) * sizeof(char *));
		arg[i] = tok;
		tok = strtok_r(NULL," ", &sptr);
	}
	arg = realloc(arg, (i+1) * sizeof(char *));
	arg[i] = NULL;
	parg = (const char **) arg;
	/* get target */
	Client *wt = NULL;
	if ( (strncasecmp(arg[0],"win",3)==0) && arg[1] ) {
		if ( !(n=atoi(arg[1])) ) {
			n = 1;
			parg = (const char **) &arg[1];
		}
		else {
			parg = (const char **) &arg[2];
		}
		if (n > 0 && n < 10) wt = winmarks[n];
		if (!wt) return;
	}
	/* process command */
	if (strncasecmp(parg[0],"bar",3) == 0) mod_bar(wt,&parg[1]);
	else if (strncasecmp(parg[0],"mon",3) == 0) monitor(wt,&parg[1]);
	else if (strncasecmp(parg[0],"foc",3) == 0) focus(wt,&parg[1]);
	else if (strncasecmp(parg[0],"flo",3) == 0) floater(wt,&parg[1]);
	else if (strncasecmp(parg[0],"ful",3) == 0) fullscreen(wt,&parg[1]);
	else if (strncasecmp(parg[0],"spl",3) == 0) conftile(wt,&parg[0]);
	else if (strncasecmp(parg[0],"gap",3) == 0) conftile(wt,&parg[0]);
	else if (strncasecmp(parg[0],"num",3) == 0) conftile(wt,&parg[0]);
	else if (strncasecmp(parg[0],"lay",3) == 0) layout(wt,&parg[1]);
	else if (strncasecmp(parg[0],"exe",3) == 0) spawn(wt,&parg[1]);
	else if (strncasecmp(parg[0],"mov",3) == 0) move(wt,&parg[1]);
	else if (strncasecmp(parg[0],"kil",3) == 0) killclient(wt,&parg[1]);
	else if (strncasecmp(parg[0],"qui",3) == 0) running = False;
	else if (strncasecmp(parg[0],"tag",3) == 0) tag(wt,&parg[1]);
	else if (strncasecmp(parg[0],"mar",3) == 0) mark_client(wt, &parg[1]);
	else if (strncasecmp(parg[0],"vie",3) == 0) {
		n = (m->tags<<16) & 0xFFFF0000;
		n |= (m->tags>>16) & 0xFFFF;
		m->tags = n;
	}
	free(arg);
	free(tmp);
	tile();
}

Added src/actions.h.







































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#ifndef __ACTIONS_H__
#define __ACTIONS_H__

extern int command(const char *);
extern void conftile(Client *, const char **);
extern void float_full(Client *, const char **);
extern void focus(Client *, const char **);
extern void killclient(Client *, const char **);
extern void layout(Client *, const char **);
extern void mod_bar(Client *, const char **);
extern void move(Client *, const char **);
extern void pull_client(Client *);
extern void push_client(Client *, Client *);
extern void spawn(Client *, const char **);
extern void tag(Client *, const char **);
extern void word(const char *);

#endif /* __ACTIONS_H__ */

Added src/alopex.c.





























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

#include "alopex.h"

extern int xlib_init(const char *);
extern int xlib_free();
extern int main_loop();

void handler(int sig) {
	if (sig == SIGCHLD)
		while (waitpid(-1, NULL, WNOHANG) > 0);
}

void die(const char *fmt, ...) {
	fprintf(stderr,"ALOPEX: ");
	va_list arg;
	va_start(arg, fmt);
	vfprintf(stderr, fmt, arg);
	va_end(arg);
	fprintf(stderr,"\n");
	exit(1);
}

int main(int argc, const char **argv) {
	signal(SIGCHLD, &handler);
	if (argc > 1) xlib_init(argv[1]);
	else xlib_init(NULL);
	main_loop();
	xlib_free();
	return 0;
}

Added src/alopex.h.















































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

#ifndef __ALOPEX_H__
#define __ALOPEX_H__

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <locale.h>
#include <math.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/Xresource.h>
#include <X11/extensions/Xinerama.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <cairo.h>
#include <cairo-xlib.h>
#include <cairo-ft.h>

#define BAR_BOTTOM		0x1000
#define BAR_HIDE			0x2000
#define BAR_HEIGHT		0x00FF
#define ATTACH_TOP		0x0000
#define ATTACH_ABOVE		0x0001
#define ATTACH_BELOW		0x0002
#define ATTACH_BOTTOM	0x0003
#define MONOCLE			0x0000
#define RSTACK				0x0001
#define BSTACK				0x0002
#define LAST_MODE			0x0003

#define WIN_FLOAT       0x0001
#define WIN_FULL_TEST   0x0002
#define WIN_FULL        0x0003
#define WIN_TRANS       0x0005
#define WIN_FOCUS       0x0010
#define WIN_URGENT      0x0020

#define NWINMARKS			10

#define MAX_STATUS 4
/* pre-tags, post-tags, 2nd right, last right */

enum {
	TabOffset,
	TabBackground, TabBorder, TabText,
	TabFocusBackground, TabFocusBorder, TabFocusText,
	TabTopBackground, TabTopBorder, TabTopText,
	StatusOffset,
	StatusBackground, StatusBorder, StatusText,
	TagOccupied, TagView, TagAlt, TagBoth,
	ThemeLast
};

enum {
	WM_PROTOCOLS, WM_DELETE_WINDOW, WM_STATE, WM_TAKE_FOCUS,
	WM_NAME,
	NET_SUPPORTED, NET_WM_NAME, NET_WM_STATE,
	NET_WM_STATE_FULLSCREEN, NET_ACTIVE_WINDOW,
	NET_WM_WINDOW_TYPE, NET_WM_TYPE_DIALOG, NET_CLIENT_LIST,
	ATOM_LAST
};

enum { TAG_ICON_TEXT, TAG_TEXT_ICON, TAG_TEXT, TAG_ICON };

typedef struct Key {
	unsigned short int mod;
	KeySym keysym;
	const char *arg;
} Key;

typedef struct Client Client;
struct Client {
	Client *next;
	Window win, parent;
	char *title;
	cairo_surface_t *icon;
	int tags, flags, x, y, w, h;
};

typedef struct Rule {
	const char *name;
	const char *class;
	int tags;
	int flags;
} Rule;

typedef struct Bar {
	cairo_surface_t *buf;
	cairo_t *ctx;
	int opts;
	int xoff, w, h;
} Bar;

typedef struct Container Container;
struct Container {
	Container *next;
	Window win;
	cairo_t *ctx;
	int x, y, w, h, n, nn;
	int left_pad, right_pad;
	Bar *bar;
	Client *top;
};

typedef struct Margin {
	int top, bottom, left, right;
} Margin;

typedef struct Monitor Monitor;
struct Monitor {
	Bar tbar;
	Monitor *next;
	Margin margin;
	int x, y, w, h, gap;
	int tags, occ, mode, split;
	Container *container, *focus;
	cairo_surface_t *bg;
};

typedef union Theme {
	struct { double x, y, w, h, r; };
	struct { double R, G, B, A, e; };
} Theme;

typedef struct Config {
	cairo_font_face_t *font, *bfont;
	Theme theme[ThemeLast];
	Margin margin;
	int nkeys;
	Key *key;
	int nrules;
	Rule *rule;
	int statfd;
	FILE *stat;
	char **tag_name;
	int *tag_icon, tag_count, tag_mode;
	int gap, split, mode, bar_pad, chain_delay, bar_opts, attach;
	int font_size;
	Bool focus_follow;
} Config;

Monitor *mons, *m;
Client *clients, *winmarks[NWINMARKS+1];
Display *dpy;
int scr;
Window root;
GC gc;
Atom atom[ATOM_LAST];
Bool running;
FT_Library ftlib;
Config conf;
Bar sbar[MAX_STATUS];

extern void die(const char *, ...);
extern int tile();

#endif /* __ALOPEX_H__ */

Added src/atoms.c.





































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

#include "alopex.h"

static inline Atom make_atom(const char *a) {
	return XInternAtom(dpy, a, False);
}

int atoms_init() {
	atom[WM_NAME] = XA_WM_NAME;
	atom[WM_PROTOCOLS] = make_atom("WM_PROTOCOLS");
	atom[WM_DELETE_WINDOW] = make_atom("WM_DELETE_WINDOW");
	atom[WM_STATE] = make_atom("WM_STATE");
	atom[WM_TAKE_FOCUS] = make_atom("WM_TAKE_FOCUS");
//	atom[NET_SUPPORTED] = make_atom("_NET_SUPPORTED");
	atom[NET_WM_NAME] = make_atom("_NET_WM_NAME");
//	atom[NET_WM_STATE] = make_atom("_NET_WM_STATE");
//	atom[NET_WM_STATE_FULLSCREEN] = make_atom("_NET_WM_STATE_FULLSCREEN");
//	atom[NET_ACTIVE_WINDOW] = make_atom("_NET_ACTIVE_WINDOW");
//	atom[NET_WM_WINDOW_TYPE] = make_atom("_NET_WM_WINDOW_TYPE");
//	atom[NET_WM_TYPE_DIALOG] = make_atom("_NET_WM_TYPE_DIALOG");
//	atom[NET_CLIENT_LIST] = make_atom("_NET_CLIENT_LIST");
	return 0;
}

Atom get_atom(Client *c, int type) {
	int i;
	unsigned long ul;
	unsigned char *uc = NULL;
	Atom aa, at = None;
	if (!XGetWindowProperty(dpy, c->win, atom[type], 0L, sizeof(at),
			False, XA_ATOM, &aa, &i, &ul, &ul, &uc) == Success && uc)
		return at;
	at = *(Atom *)uc;
	XFree(uc);
	return at;
}

char *get_text(Client *c, int type) {
	char **strs = NULL, *ret = NULL;
	int n;
	XTextProperty text;
	XGetTextProperty(dpy, c->win, &text, atom[type]);
	if (!text.nitems) return NULL;
	if (text.encoding == XA_STRING) ret = strdup(text.value);
	else if (XmbTextPropertyToTextList(dpy, &text, &strs, &n)>=Success) {
		ret = strdup(*strs);
		XFreeStringList(strs);
	}
	XFree(text.value);
	return ret;
}


int send_message(Client *c, int type, int msg) {
	XEvent ev;
	ev.type = ClientMessage;
	ev.xclient.window = c->win;
	ev.xclient.message_type = atom[type];
	//ev.xclient.message_type = XInternAtom(dpy, "WM_PROTOCOLS", True);
	ev.xclient.format = 32;
	ev.xclient.data.l[0] = atom[msg];
	//ev.xclient.data.l[0] = XInternAtom(dpy, "WM_DELETE_WINDOW", True);
	ev.xclient.data.l[1] = CurrentTime;
	XSendEvent(dpy, c->win, False, NoEventMask, &ev);
	return 0;
}

Added src/config.c.





























































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

#include "alopex.h"

extern int free_mons();
extern int get_mons(const char *, const char *);
extern int icons_init(const char *);
extern int icons_free();

static int config_general(XrmDatabase, const char *);
static int config_binds(XrmDatabase, const char *);
static int config_rules(XrmDatabase, const char *);
static int config_theme(XrmDatabase, const char *);

FT_Face face, bface;
static pid_t pid;
static XrmDatabase xrdb;

int config_init(const char *theme) {
	const char *pwd = getenv("PWD");
	XrmInitialize();
	if ( (!chdir(getenv("XDG_CONFIG_HOME")) && !chdir("alopex")) ||
			(!chdir(getenv("HOME")) && !chdir(".config/alopex")) )
		xrdb = XrmGetFileDatabase("config");
	if (!xrdb) xrdb = XrmGetFileDatabase("/usr/share/alopex/config");
	if (!xrdb) die("cannot find a configuration resource database");
	char *_base = "icecap", *class = "Alopex.Theme", *type;
	const char *base;
	XrmValue val;
	if (theme) base = theme;
	else if (XrmGetResource(xrdb, class, class, &type, &val))
		base = val.addr;
	else base = _base;
char test[256];
sprintf(test, "%s.Tab.Offset", base);
if (!XrmGetResource(xrdb, test, test, &type, &val))
die("No theme resources found\n");
	config_binds(xrdb, base);
	config_general(xrdb, base);
	config_rules(xrdb, base);
	config_theme(xrdb, base);
	chdir(pwd);
	return 0;
}

int config_free() {
	XrmDestroyDatabase(xrdb);
	if (conf.statfd) {
		fclose(conf.stat);
		close(conf.statfd);
		conf.statfd = 0;
		kill(pid, SIGKILL);
		wait(pid);
	}
	icons_free();
	free_mons();
	int i;
	if (conf.tag_name) {
		for (i = 0; conf.tag_name[i]; i++)
			free(conf.tag_name[i]);
		free(conf.tag_name);
	}
	if (conf.tag_icon) free(conf.tag_icon);
	cairo_font_face_destroy(conf.font);
	cairo_font_face_destroy(conf.bfont);
	FT_Done_Face(face);
	FT_Done_Face(bface);
	free(conf.key);
	conf.key = NULL;
	conf.nkeys = 0;
	return 0;
}

int reconfigure() {
	config_free();
	config_init(NULL);
}

/**** Local functions ****/

enum {
	STR_Font, STR_BoldFont, STR_IconFile, STR_Options, STR_Background,
	STR_Containers, STR_Names, STR_Icons, STR_FollowMouse, STR_Attach,
	STR_StatIn, STR_Mode, STR_Margin, STR_TagMode,
	STR_Last
};
enum { TYPE_S, TYPE_D };
typedef struct Res {
	const char *elem, *opt;
	int type;
	void *dest;
} Res;

int config_general(XrmDatabase xrdb, const char *base) {
	const char *s[STR_Last];
	memset(s, 0, STR_Last);
	int bar_height = 0;
	const char *RES_Bar = "Bar";
	const char *RES_Background = "Background";
	const char *RES_Mode = "Mode";
	const char *RES_Tags = "Tags";
	const char *RES_Tiling = "Tiling";
	const char *RES_Padding = "Padding";
	const char *RES_Clients = "Clients";
	Res res[] = {
		{ RES_Bar,    "StatInput",    TYPE_S, &s[STR_StatIn]},
		{ RES_Bar,    "Font",         TYPE_S, &s[STR_Font]},
		{ RES_Bar,    "BoldFont",     TYPE_S, &s[STR_BoldFont]},
		{ RES_Bar,    "FontSize",     TYPE_D, &conf.font_size},
		{ RES_Bar,    "Height",       TYPE_D, &bar_height},
		{ RES_Bar,    "Icons",        TYPE_S, &s[STR_IconFile]},
		{ RES_Bar,    "Options",      TYPE_S, &s[STR_Options]},
		{ RES_Tiling, RES_Background, TYPE_S, &s[STR_Background]},
		{ RES_Tiling, "Split",        TYPE_D, &conf.split},
		{ RES_Tiling, RES_Padding,    TYPE_D, &conf.gap},
		{ RES_Tiling, "Containers",   TYPE_S, &s[STR_Containers]},
		{ RES_Tiling, RES_Mode,       TYPE_S, &s[STR_Mode]},
		{ RES_Tiling, "Margin",       TYPE_S, &s[STR_Margin]},
		{ RES_Tags,   RES_Mode,       TYPE_S, &s[STR_TagMode]},
		{ RES_Tags,   "Names",        TYPE_S, &s[STR_Names]},
		{ RES_Tags,   "Icons",        TYPE_S, &s[STR_Icons]},
		{ RES_Tags,   RES_Padding,    TYPE_D, &conf.bar_pad},
		{ "Chains",   "Delay",        TYPE_D, &conf.chain_delay},
		{ RES_Clients,"FollowMouse",  TYPE_S, &s[STR_FollowMouse]},
		{ RES_Clients,"Attach",       TYPE_S, &s[STR_Attach]},
	};
	int i;
	char class[256], *type;
	XrmValue val;
	for (i = 0; i < sizeof(res)/sizeof(res[0]); i++) {
		strcpy(class,base);
		strcat(class,"."); strcat(class,res[i].elem);
			strcat(class,"."); strcat(class,res[i].opt);
		if (!XrmGetResource(xrdb, class, class, &type, &val)) continue;
		if (res[i].type == TYPE_S)
			*(char **) res[i].dest = val.addr;
		else if (res[i].type == TYPE_D)
			 *((int *) res[i].dest) = atoi(val.addr);
	}
	/* get fonts */
	if (FT_New_Face(ftlib, s[STR_Font], 0, &face) |
			FT_Set_Pixel_Sizes(face, 0, conf.font_size))
		die("unable to load freetype font \"%s\"",s[STR_Font]);
	if (FT_New_Face(ftlib, s[STR_BoldFont], 0, &bface) |
			FT_Set_Pixel_Sizes(bface, 0, conf.font_size))
		die("unable to load freetype font \"%s\"",s[STR_BoldFont]);
	conf.font = cairo_ft_font_face_create_for_ft_face(face, 0);
	conf.bfont = cairo_ft_font_face_create_for_ft_face(bface, 0);
	/* set options */
	conf.bar_opts = (bar_height ? bar_height : conf.font_size + 4);
	if (strcasestr(s[STR_Mode],"rstack")) conf.mode = RSTACK;
	if (strcasestr(s[STR_Mode],"bstack")) conf.mode = BSTACK;
	if (strcasestr(s[STR_Mode],"monocle")) conf.mode = MONOCLE;
	if (strcasestr(s[STR_Options],"bottom")) conf.bar_opts |= BAR_BOTTOM;
	if (strcasestr(s[STR_Options],"hide")) conf.bar_opts |= BAR_HIDE;
	if (strcasestr(s[STR_FollowMouse],"true")) conf.focus_follow = True;
	if (strcasestr(s[STR_Attach],"top")) conf.attach = ATTACH_TOP;
	if (strcasestr(s[STR_Attach],"above")) conf.attach = ATTACH_ABOVE;
	if (strcasestr(s[STR_Attach],"below")) conf.attach = ATTACH_BELOW;
	if (strcasestr(s[STR_Attach],"bottom")) conf.attach = ATTACH_BOTTOM;
	if (s[STR_Margin]) sscanf(s[STR_Margin],"%d %d %d %d",
			&conf.margin.top, &conf.margin.bottom,
			&conf.margin.left, &conf.margin.right);
	if (!strcasecmp(s[STR_TagMode],"icon-text"))
		conf.tag_mode = TAG_ICON_TEXT;
	else if (!strcasecmp(s[STR_TagMode],"text-icon"))
		conf.tag_mode = TAG_TEXT_ICON;
	else if (!strcasecmp(s[STR_TagMode],"text"))
		conf.tag_mode = TAG_TEXT;
	else if (!strcasecmp(s[STR_TagMode],"icon"))
		conf.tag_mode = TAG_ICON;
	/* get tag names and icon numbers */
	conf.tag_name = NULL;
	char *name = strtok((char *) s[STR_Names]," ");
	for (i = 0; name; i++) {
		conf.tag_name = realloc(conf.tag_name, (i+1) * sizeof(char *));
		conf.tag_name[i] = strdup(name);
		name = strtok(NULL," ");
	}
	conf.tag_count = i;
	conf.tag_name = realloc(conf.tag_name, (i+1) * sizeof(char *));
	conf.tag_name[i] = NULL;
	conf.tag_icon = NULL;
	name = strtok((char *) s[STR_Icons]," ");
	for (i = 0; name; i++) {
		conf.tag_icon = realloc(conf.tag_icon, (i+1) * sizeof(int));
		conf.tag_icon[i] = atoi(name);
		name = strtok(NULL," ");
	}
	if (conf.tag_count < i) conf.tag_count = i;
	conf.tag_icon = realloc(conf.tag_icon, (i+1) * sizeof(int));
	conf.tag_icon[i] = -1;
	/* status input */
	int fd[2], flags;
	struct stat stbuf;
	if (s[STR_StatIn] && !stat(s[STR_StatIn],&stbuf) &&
			(stbuf.st_mode & S_IXUSR) ){
		pipe(fd);
		if ( (pid=fork()) ) {
			close(fd[1]);
			flags = fcntl(fd[0], F_GETFL, 0);
			fcntl(fd[0], F_SETFL, flags | O_NONBLOCK);
			conf.statfd = fd[0];
			conf.stat = fdopen(fd[0],"r");
		}
		else {
			close(ConnectionNumber(dpy));
			close(fd[0]);
			dup2(fd[1], 1);
		//	close(fd[1]);
			execlp(s[STR_StatIn], s[STR_StatIn], NULL);
		}
	}
	else {
		conf.statfd = 0;
		conf.stat = NULL;
	}
	/* external inits */
	get_mons(s[STR_Background], s[STR_Containers]);
	icons_init(s[STR_IconFile]);
	return 0;
}

#define MAX_MOD	6
int config_binds(XrmDatabase xrdb, const char *base) {
	/* get modifiers */
	int mods[MAX_MOD];
	memset(mods,0,MAX_MOD);
	const char *ord[MAX_MOD] = {
		"None", "First", "Second", "Third", "Fourth", "Fifth"
	};
	char class[256], *type;
	XrmValue val;
	int i, j, tmod;
	for (i = 1; i < MAX_MOD; i++) {
		sprintf(class,"%s.Bind.Mod.%s",base,ord[i]);
		if (XrmGetResource(xrdb, class, class, &type, &val)) {
			mods[i] = 0;
			if (strcasestr(val.addr, "mod5"))
				mods[i] |= Mod5Mask;
			if (strcasestr(val.addr,"super") ||
					strcasestr(val.addr, "win") ||
					strcasestr(val.addr, "mod4"))
				mods[i] |= Mod4Mask;
			if (strcasestr(val.addr, "mod3"))
				mods[i] |= Mod3Mask;
			if (strcasestr(val.addr, "mod2"))
				mods[i] |= Mod2Mask;
			if (strcasestr(val.addr, "alt") ||
					strcasestr(val.addr, "mod1"))
				mods[i] |= Mod1Mask;
			if (strcasestr(val.addr, "control") ||
					strcasestr(val.addr,"ctrl"))
				mods[i] |= ControlMask;
			if (strcasestr(val.addr, "shift"))
				mods[i] |= ShiftMask;
		}
	}
	/* loop through bindings */
	conf.key = NULL;
	conf.nkeys = 0;
	int bmax = 100;
//	sprintf(class,"%s.Bind.Max",base);
//	if (XrmGetResource(xrdb, class, class, &type, &val))
//		bmax = atoi(val.addr) + 1;
	KeySym sym;
	for (i = 0; i < bmax; i++) {
		sprintf(class,"%s.Bind.%02d.Key",base,i);
		if (!XrmGetResource(xrdb, class, class, &type, &val)) continue;
		if ( (sym=XStringToKeysym(val.addr)) == NoSymbol ) continue;
		for (j = 0; j < MAX_MOD; j++) {
			sprintf(class,"%s.Bind.%02d.%s",base,i,ord[j]);
			if (!XrmGetResource(xrdb, class, class, &type, &val)) continue;
			conf.key = realloc(conf.key, (conf.nkeys+1) * sizeof(Key));
			conf.key[conf.nkeys].keysym = sym;
			conf.key[conf.nkeys].mod = mods[j];
			conf.key[conf.nkeys].arg = val.addr;
			conf.nkeys++;
		}
	}
	return 0;
}

int config_rules(XrmDatabase xrdb, const char *base) {
	char class[256], *type, *rn, *rc;
	XrmValue val;
	conf.rule = NULL;
	conf.nrules = 0;
	int i, j, rmax = 100, tags, flags, n[8];
//	sprintf(class,"%s.Rule.Max",base);
//	if (XrmGetResource(xrdb, class, class, &type, &val))
//		rmax = atoi(val.addr) + 1;
	for (i = 0; i < rmax; i++) {
		rn = rc = NULL;
		sprintf(class,"%s.Rule.%02d.Name",base,i);
		if (XrmGetResource(xrdb, class, class, &type, &val)) rn = val.addr;
		sprintf(class,"%s.Rule.%02d.Class",base,i);
		if (XrmGetResource(xrdb, class, class, &type, &val)) rc = val.addr;
		if (!rn && !rc) continue;
		conf.rule = realloc(conf.rule, (conf.nrules+1) * sizeof(Rule));
		conf.rule[conf.nrules].name = rn;
		conf.rule[conf.nrules].class = rc;
		conf.rule[conf.nrules].tags = 0;
		sprintf(class,"%s.Rule.%02d.Tags",base,i);
		if (XrmGetResource(xrdb, class, class, &type, &val)) {
			memset(n,0,8 * sizeof(int));
			sscanf(val.addr,"%d %d %d %d %d %d %d %d",
					&n[0], &n[1], &n[2], &n[3], &n[4], &n[5], &n[6], &n[7]);
			for (j = 0; j < 8; j++)
				if (n[j]) conf.rule[conf.nrules].tags |= (1<<(n[j]-1));
		}
		conf.rule[conf.nrules].flags = 0;
		sprintf(class,"%s.Rule.%02d.Flags",base,i);
		if (XrmGetResource(xrdb, class, class, &type, &val)) {
			if (strcasestr(val.addr,"fullscreen"))
				conf.rule[conf.nrules].flags |= WIN_FULL;
			if (strcasestr(val.addr,"float"))
				conf.rule[conf.nrules].flags |= WIN_FLOAT;
		}
		conf.nrules++;
	}
	return 0;
}

int config_theme(XrmDatabase xrdb, const char *base) {
	const char *RES_Tab = "Tab";
	const char *RES_TabFocus = "TabFocus";
	const char *RES_TabTop = "TabTop";
	const char *RES_Status = "Status";
	const char *RES_Tag = "Tag";
	const char *RES_Offset = "Offset";
	const char *RES_Background = "Background";
	const char *RES_Border = "Border";
	const char *RES_Text = "Text";
	Res res[] = {
		{ RES_Tab,       RES_Offset,     TabOffset,          NULL},
		{ RES_Tab,       RES_Background, TabBackground,      NULL},
		{ RES_Tab,       RES_Border,     TabBorder,          NULL},
		{ RES_Tab,       RES_Text,       TabText,            NULL},
		{ RES_TabFocus,  RES_Background, TabFocusBackground, NULL},
		{ RES_TabFocus,  RES_Border,     TabFocusBorder,     NULL},
		{ RES_TabFocus,  RES_Text,       TabFocusText,       NULL},
		{ RES_TabTop,    RES_Background, TabTopBackground,   NULL},
		{ RES_TabTop,    RES_Border,     TabTopBorder,       NULL},
		{ RES_TabTop,    RES_Text,       TabTopText,         NULL},
		{ RES_Status,    RES_Offset,     StatusOffset,       NULL},
		{ RES_Status,    RES_Background, StatusBackground,   NULL},
		{ RES_Status,    RES_Border,     StatusBorder,       NULL},
		{ RES_Status,    RES_Text,       StatusText,         NULL},
		{ RES_Tag,       "Occupied",     TagOccupied,        NULL},
		{ RES_Tag,       "View",         TagView,            NULL},
		{ RES_Tag,       "Alt",          TagAlt,             NULL},
		{ RES_Tag,       "Both",         TagBoth,            NULL},
	};
	char class[256], *type;
	XrmValue val;
	int i;
	Theme *q;
	for (i = 0; i < sizeof(res)/sizeof(res[0]); i++) {
		sprintf(class,"%s.%s.%s", base, res[i].elem, res[i].opt);
		if (!XrmGetResource(xrdb, class, class, &type, &val)) continue;
		q = &conf.theme[res[i].type];
		sscanf(val.addr,"%lf %lf %lf %lf %lf",
			&q->R, &q->G, &q->B, &q->A, &q->e);
	}
	return 0;
}

Added src/draw.c.























































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

#include "alopex.h"

static int round_rect(Bar *, int, int, int, int, int, int, int, int);
static int set_color(cairo_t *, int);
static int sbar_icon(Bar *, int, Bool);
static int sbar_text(Bar *, const char *);

static cairo_surface_t *icon_img[100];
static cairo_format_t icon_fmt = 0;

int draw_bar_sub(Monitor *M, Container *C, Bar *S, int x, Bool bg) {
	if (C->bar->opts & BAR_HIDE) return 0;
	if (S->w < 1) return 0;
	cairo_rectangle(C->bar->ctx, x, 0, S->w, C->bar->h);
	cairo_clip(C->bar->ctx);
	if (bg) { /* draw background as needed */
		int y = M->y - (C->bar->opts & BAR_BOTTOM ? C->y+C->h : C->y-C->bar->h);
		if (C->top)
			cairo_set_source_surface(C->bar->ctx, M->bg, M->x - C->x, y);
		else
			cairo_set_source_surface(C->bar->ctx, M->bg, M->x - C->x, 0);
		cairo_paint(C->bar->ctx);
	}
	round_rect(C->bar, x, 0, S->w, S->h, StatusOffset,
			StatusBackground, StatusBorder, StatusText);
	cairo_set_source_surface(C->bar->ctx, S->buf, x, 0);
	cairo_paint(C->bar->ctx);
	cairo_reset_clip(C->bar->ctx);
	return 0;
}

int draw_bars(Bool bg) {
	Monitor *M; Container *C;
	int n, count;
	for (M = mons; M; M = M->next) {
		count = n = 0;
		for (C = M->container; C; C = C->next) if (C->top) count++;
		for (C = M->container; C; C = C->next) {
			/* paint status to buf */
			if (n == 0) {
				draw_bar_sub(M, C, &sbar[0], 0, bg);
				draw_bar_sub(M, C, &M->tbar, sbar[0].w, bg);
				draw_bar_sub(M, C, &sbar[1], sbar[0].w + M->tbar.w, bg);
				if (count < 2) {
					draw_bar_sub(M, C, &sbar[2], C->w-sbar[2].w-sbar[3].w, bg);
					draw_bar_sub(M, C, &sbar[3], C->w - sbar[3].w, bg);
				}
			}
			else if (n == 1) {
				if (count == 2) {
					draw_bar_sub(M, C, &sbar[2], C->w-sbar[2].w-sbar[3].w, bg);
					draw_bar_sub(M, C, &sbar[3], C->w - sbar[3].w, bg);
				}
				else  {
					draw_bar_sub(M, C, &sbar[2], C->w - sbar[2].w, bg);
				}
			}
			else if (n == count - 1) {
				draw_bar_sub(M, C, &sbar[3], C->w - sbar[3].w, bg);
			}
			/* paint buf to win */
			cairo_set_source_surface(C->ctx, C->bar->buf, 0, 0);
			cairo_paint(C->ctx);
			if ( (++n) >= count ) break;
		}
	}
}

int draw_tab(Container *C, Client *c, int n, int count) {
	Bar *b = C->bar;
	int w = (C->w - C->left_pad - C->right_pad)/ count;
	int x = w * n + C->left_pad;
	int h = C->bar->opts & BAR_HEIGHT;
	int theme = 0;
	if (m->focus == C && C->top == c) theme = 3;
	else if (C->top == c) theme = 6;
	round_rect(b, x, 0, w, h, TabOffset, TabBackground + theme,
			TabBorder + theme, TabText + theme);
	double off = conf.theme[TabText+theme].r;
	cairo_text_extents_t ext;
	cairo_text_extents(b->ctx, c->title, &ext);
if (c->icon) ext.x_advance += conf.font_size + conf.bar_pad;
	if (off < 0) off *= -1;
	else {
		off *= w - ext.x_advance;
		if (off < 0) off = 0;
	}
if (c->icon) {
	cairo_save(b->ctx);
	cairo_set_source_surface(b->ctx, c->icon, x + off,
			(b->h - conf.font_size) / 2.0);
	cairo_paint(b->ctx);
	off += conf.font_size + conf.bar_pad;
	cairo_restore(b->ctx);
}
	cairo_rectangle(b->ctx, x+off, 0, w-off, h);
	cairo_clip(b->ctx);
	cairo_move_to(b->ctx, x+off, h - 4); // - 4 ?
	cairo_show_text(b->ctx, c->title);
	cairo_reset_clip(b->ctx);
}

int icons_init(const char *fname) {
	double iw, ih;
	int i, j, fs = conf.font_size;
	cairo_surface_t *img = cairo_image_surface_create_from_png(fname);
if (cairo_surface_status(img) != CAIRO_STATUS_SUCCESS) return 1;
	icon_fmt = cairo_image_surface_get_format(img);
	iw = cairo_image_surface_get_width(img) / 10.0;
	ih = cairo_image_surface_get_height(img) / 10.0;
	cairo_t *ctx;
	for (j = 0; j < 10; j++) for (i = 0; i < 10; i++) {
		icon_img[j*10+i] = cairo_image_surface_create(icon_fmt, fs, fs);
		ctx = cairo_create(icon_img[j*10+i]);
		cairo_scale(ctx, fs/iw, fs/ih);
		cairo_set_source_surface(ctx, img, -1 * i * iw, -1 * j * ih);
		cairo_paint(ctx);
		cairo_destroy(ctx);
	}
	cairo_surface_destroy(img);
	return 0;
}

int icons_free() {
	int i;
	for (i = 0; i < 100; i++)
		if (icon_img[i]) cairo_surface_destroy(icon_img[i]);
	return 0;
}

int round_rect(Bar *b, int x, int y, int w, int h,
		int off, int bg, int brd, int txt) {
	const Theme *q = &conf.theme[off];
	if (b->opts & BAR_BOTTOM) {
		cairo_save(b->ctx);
		cairo_scale(b->ctx, 1, -1);
		cairo_translate(b->ctx, 0, -1 * (b->opts & BAR_HEIGHT));
	}
	cairo_new_sub_path(b->ctx);
	x += q->x; y += q->y; w += q->w; h += q->h;
	cairo_arc(b->ctx, x + w - q->e, y + q->e, q->e, -0.5 * M_PI, 0);
	cairo_arc(b->ctx, x + w - q->e, y + h - q->e, q->e, 0, 0.5 * M_PI);
	cairo_arc(b->ctx, x + q->e, y + h - q->e, q->e, 0.5 * M_PI, M_PI);
	cairo_arc(b->ctx, x + q->e, y + q->e, q->e, M_PI, 1.5 * M_PI);
	cairo_close_path(b->ctx);
	set_color(b->ctx, bg);
	cairo_fill_preserve(b->ctx);
	set_color(b->ctx, brd);
	cairo_set_line_width(b->ctx, conf.theme[brd].r);
	cairo_stroke(b->ctx);
	if (b->opts & BAR_BOTTOM) cairo_restore(b->ctx);
	set_color(b->ctx, txt);
	return 0;
}

int sbar_icon(Bar *S, int n, Bool col) {
// TODO fix the "2"
	if ( (--n) < 0 || n > 99) return 1;
	if (!icon_img[n]) return 1;
	cairo_save(S->ctx);
	if (col && icon_fmt != CAIRO_FORMAT_A1) {
		cairo_set_source_surface(S->ctx, icon_img[n], S->xoff, 2);
		cairo_paint(S->ctx);
	}
	else {
		cairo_mask_surface(S->ctx, icon_img[n], S->xoff, 2);
	}
	S->xoff += conf.font_size;
	cairo_restore(S->ctx);
	return 0;
}

int sbar_parse(Bar *S, const char *s) {
	cairo_save(S->ctx);
	cairo_set_operator(S->ctx, CAIRO_OPERATOR_CLEAR);
	cairo_paint(S->ctx);
	cairo_restore(S->ctx);
	S->xoff = 0;
	set_color(S->ctx, StatusText);
	const char *c; char *t1, *t2, *str;
	double r, g, b, a;
	for (c = s; c && *c != '&' && *c != '\0' && *c != '\n'; c++) {
		if (*c == '{') {
			if (*(++c) == 'i') sbar_icon(S, atoi((++c)), True);
			else if (*c == 'I') sbar_icon(S, atoi((++c)), False);
			else if (*c == 'f') cairo_set_font_face(S->ctx, conf.font);
			else if (*c == 'F') cairo_set_font_face(S->ctx, conf.bfont);
			else if (sscanf(c, "%lf %lf %lf %lf", &r, &g, &b, &a) == 4)
				cairo_set_source_rgba(S->ctx, r, g, b, a);
			c = strchr(c, '}');
		}
		else {
			str = strdup(c);
			t1 = strchr(str,'{');
			t2 = strchr(str,'&');
			if (t1 && t2 && t1 > t2) t1 = t2;
			else if (!t1 && t2) t1 = t2;
			if (!t1) t1 = strchr(str,'\n');
			*t1 = '\0';
			c += t1 - str - 1;
			sbar_text(S, str);
			free(str);
		}
	}
	if (S->w != S->xoff) {
		S->w = S->xoff;
		return 1;
	}
	else return 0;
}

static int sbar_tag_icon(Monitor *M, Bar *S, int i) {
	if (conf.tag_icon[i] == -1) return 1;
	else return sbar_icon(S, conf.tag_icon[i], True); //TODO: True -> conf
}

static int sbar_tag_text(Monitor *M, Bar *S, int i) {
	if (conf.tag_name[i][0] == '-') return 1;
	sbar_text(S, conf.tag_name[i]);
	S->xoff += conf.bar_pad;
	return 1;
}

int sbar_tags(Monitor *M) {
	if (M->container->bar->opts & BAR_HIDE) return 0;
	Bar *S = &M->tbar;
	cairo_save(S->ctx);
	cairo_set_operator(S->ctx, CAIRO_OPERATOR_CLEAR);
	cairo_paint(S->ctx);
	cairo_restore(S->ctx);
	S->xoff = conf.bar_pad;
	int i, count = 0;
	for (i = 0; conf.tag_name[i]; i++) {
		set_color(S->ctx, TagOccupied);
		if (M->occ & (1<<i)) cairo_set_font_face(S->ctx, conf.bfont);
		else cairo_set_font_face(S->ctx, conf.font);
		if ( (M->tags & (1<<i)) && (M->tags & (1<<(1+16))) )
			set_color(S->ctx, TagBoth);
		else if (M->tags & (1<<i)) set_color(S->ctx, TagView);
		else if (M->tags & (1<<(i+16))) set_color(S->ctx, TagAlt);
		else if (!(M->occ & (1<<i))) continue;
		switch (conf.tag_mode) {
			case TAG_ICON_TEXT: count += sbar_tag_icon(M, S, i);
			case TAG_TEXT: count += sbar_tag_text(M, S, i); break;
			case TAG_TEXT_ICON: count += sbar_tag_text(M, S, i);
			case TAG_ICON: count += sbar_tag_icon(M, S, i); break;
		}
	}
	if (!count) S->xoff = 0;
	S->w = S->xoff;
	return 0;
}

int sbar_text(Bar *S, const char *str) {
	cairo_move_to(S->ctx, S->xoff, S->h - 4);
	cairo_show_text(S->ctx, str);
	cairo_text_extents_t ext;
	cairo_text_extents(S->ctx, str, &ext);
	S->xoff += ext.x_advance;
	return 0;
}

int set_color(cairo_t *ctx, int col) {
	cairo_set_source_rgba(ctx, conf.theme[col].R, conf.theme[col].G,
			conf.theme[col].B, conf.theme[col].A);
}

Added src/tile.c.











































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

#include "alopex.h"

extern int draw_bars(Bool);
extern int sbar_tags(Monitor *M);

Bool tile_check(Monitor *, Client *);

static int resize_container(Monitor *, Container *, int, int);
static int tile_container(Monitor *, Container *, Client *, int);

int tile() {
	if ( !winmarks[1] || !(winmarks[1]->tags & m->tags) ) {
		winmarks[0] = winmarks[1];
		winmarks[1] = NULL;
	}
	Monitor *M;
	Container *C;
	Client *c, *pc, *t;
	int num, cn, numC, ord;
	int mview = 0;
	for (M = mons; M; M = M->next) {
		M->tags &= ~mview;
		mview |= M->tags;
		/* calculate how many containers will be used: */
		if (M->mode == MONOCLE) {
			M->focus = M->container;
			numC = 0;
			M->occ = 0;
			for (c = clients; c; c = c->next) {
				M->occ |= (c->tags & 0xFFFF);
				if (tile_check(M, c)) {
					if (!winmarks[1]) winmarks[1] = c;
					if (c == winmarks[1]) M->container->top = c;
					numC = 1;
				}
			}
		}
		else { /* {r/b}stack: */
			c = clients;
			M->occ = 0;
			for (numC = 0, C = M->container; C; C = C->next, numC++) {
				cn = (M->mode == MONOCLE ? 1024 : (C->n > 0 ? C->n : 1024));
				t = NULL;
				for (num = 0, pc = c; c && num < cn; c = c->next) {
					/* fill C up to max clients */
					M->occ |= (c->tags & 0xFFFF);
					if (tile_check(M, c)) {
						num++;
						/* set C->top */
						if (!winmarks[1]) winmarks[1] = c;
						if (c == winmarks[1]) {
							M->focus = C;
							C->top = c;
						}
						if (!t) t = c;
						if (c == C->top) t = c;
					}
				}
				if (num == 0) break;
				C->top = t;
			}
		}
		sbar_tags(M);
		/* tile each used container, hide others */
		c = clients;
		for (ord = 0, C = M->container; C && c; C = C->next, ord++) {
			cn = (M->mode == MONOCLE ? 1024 : (C->n > 0 ? C->n : 1024));
			for (num = 0, pc = c; c && num < cn; c = c->next)
				if (tile_check(M, c)) num++;
			if (!num) break;
			resize_container(M, C, numC, ord);
			tile_container(M, C, pc, num);
		}
		for (C; C; C = C->next) {
			purgatory(C->win);
			C->top = NULL;
		}
		/* show bar if no containers are visible */
		if (!numC && !(conf.bar_opts & BAR_HIDE)) {
			C = M->container;
			C->x = M->x + M->margin.left;
			C->y = M->y + (conf.bar_opts & BAR_BOTTOM ?
					M->h - C->bar->h - M->margin.bottom :
					M->margin.top);
			C->w = M->w - M->margin.left - M->margin.right;
			XMoveResizeWindow(dpy, C->win, C->x, C->y, C->w, C->bar->h);
			cairo_set_source_surface(C->bar->ctx, M->bg,
					M->x - C->x, M->y - C->y);
			cairo_paint(C->bar->ctx);
		}
		/* sort floating windows */
		for (c = clients ; c; c = c->next) {
			if (!(M->tags & c->tags)) continue;
			else if (c->flags & WIN_FULL_TEST) {
				if ( !winmarks[1] || !(winmarks[1]->flags & WIN_FLOAT))
					winmarks[1] = c;
				XMoveResizeWindow(dpy, c->win, M->x, M->y, M->w, M->h);
			}
			else if (c->flags & WIN_FLOAT) {
				XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
			}
		}
		if (!M->focus) M->focus = M->container;
	}
	for (c = clients; c; c = c->next) {
		if (!(c->tags & mview)) purgatory(c->win);
	}
	draw_bars(False);
	set_focus();
	return 0;
}


int resize_container(Monitor *M, Container *C, int numC, int ord) {
	/* get tileable region */
	int x = M->x + M->margin.left;
	int y = M->y + M->margin.top;
	int w = M->w - M->margin.left - M->margin.right;
	int h = M->h - M->margin.top - M->margin.bottom;
	int stack_size;
	/* pad for status bars */
	if (!ord) C->left_pad = sbar[0].w + sbar[1].w + M->tbar.w;
	C->right_pad = 0;
	if (ord == 1 || numC == 1) C->right_pad += sbar[2].w;
	if (ord == numC - 1 || numC == 1) C->right_pad += sbar[3].w;
	/* calculate for each tiling mode */
	if (numC == 1) { /* only one container */
		C->x = x + M->gap;
		C->y = y + M->gap;
		C->w = w - 2 * M->gap;
		C->h = h - 2 * M->gap;
	}
	else if (M->mode == RSTACK) {
		stack_size = (h - M->gap) / (numC - 1) - M->gap;
		C->x = x + M->gap + (ord ? (w -  M->gap) / 2 + M->split: 0);
		C->y = y + M->gap + (stack_size + M->gap) * (ord ? ord - 1 : 0);
		C->w = (ord ? x + w - M->gap - C->x :
				(w - M->gap) / 2 - M->gap + M->split);
		C->h = (ord ? stack_size : h - 2 * M->gap);
		if (ord == numC - 1) C->h = h - M->gap - C->y + y;
	}
	else if (M->mode == BSTACK) {
		stack_size = (w - M->gap) / (numC - 1) - M->gap;
		C->x = x + M->gap + (stack_size + M->gap) * (ord ? ord - 1 : 0);
		C->y = y + M->gap + (ord ? (h -  M->gap) / 2 + M->split: 0);
		C->w = (ord ? stack_size : w - 2 * M->gap);
		C->h = (ord ? y + h - M->gap - C->y :
				(h - M->gap) / 2 - M->gap + M->split);
		if (ord == numC - 1) C->w = w - M->gap - C->x + x;
	}
	/* adjust for bar space */
	if (!(C->bar->opts & BAR_HIDE)) {
		C->h -= C->bar->h;
		if (!(C->bar->opts & BAR_BOTTOM))
			C->y += C->bar->h;
	}
	/* hide/show the bar */
	if (C->bar->opts & BAR_HIDE) purgatory(C->win);
	else {
		int y = (C->bar->opts & BAR_BOTTOM ? C->y+C->h : C->y-C->bar->h);
		XMoveResizeWindow(dpy, C->win, C->x, y, C->w, C->bar->h);
		cairo_set_source_surface(C->bar->ctx, M->bg, M->x - C->x, M->y - y);
		cairo_paint(C->bar->ctx);
	}
}

Bool tile_check(Monitor *M, Client *c) {
	return ((M->tags & c->tags) && !(c->flags & WIN_FLOAT));
}

int tile_container(Monitor *M, Container *C, Client *pc, int num) {
	Client *c, *t = NULL;
	int n;
	for (c = pc, n = num; c && n; c = c->next) if (tile_check(M, c)) {
		XMoveResizeWindow(dpy, c->win, C->x, C->y, C->w, C->h);
		if (!(C->bar->opts & BAR_HIDE))
			draw_tab(C, c, num - n, num, C->bar->opts & BAR_BOTTOM);
		n--;
	}
}

Added src/xlib.c.















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

#include "alopex.h"
#include "actions.h"

#define SELECT_EVENTS	\
	ExposureMask | FocusChangeMask | ButtonReleaseMask | \
	SubstructureNotifyMask | SubstructureRedirectMask | \
	StructureNotifyMask | PropertyChangeMask | EnterWindowMask

#define GRABMODE	GrabModeAsync, GrabModeAsync
#define GRABMODE2	ButtonPressMask, GrabModeAsync, GrabModeAsync, \
	None, None

extern int config_init(const char *);
extern int config_free();
extern int draw_bars(Bool);
extern int sbar_parse(Bar *, const char *);
extern char *get_text(Client *, int);

static int apply_rules(Client *);
static int get_hints(Client *);
static int get_icon(Client *);
static int get_name(Client *);
static int get_size(Client *);

static void buttonpress(XEvent *);
static void configurerequest(XEvent *);
static void enternotify(XEvent *);
static void expose(XEvent *);
static void keypress(XEvent *);
static void propertynotify(XEvent *);
static void maprequest(XEvent *);
static void unmapnotify(XEvent *);

static int purgX, purgY;
static void (*handler[LASTEvent]) (XEvent *) = {
	[ButtonPress]       = buttonpress,
	[ConfigureRequest]  = configurerequest,
	[EnterNotify]       = enternotify,
	[Expose]            = expose,
	[KeyPress]          = keypress,
	[MapRequest]        = maprequest,
	[PropertyNotify]    = propertynotify,
	[UnmapNotify]       = unmapnotify,
};

int free_mons(const char *bg, const char *cont) {
	int i;
	Monitor *M;
	Container *C;
	for (M = mons; M; M = M->next) {
		for (C = M->container; C; C = C->next) {
			cairo_destroy(C->bar->ctx);
			cairo_surface_destroy(C->bar->buf);
			free(C->bar);
			cairo_destroy(C->ctx);
			XDestroyWindow(dpy, C->win);
		}
		cairo_destroy(M->tbar.ctx);
		cairo_surface_destroy(M->tbar.buf);
		free(M->container);
		cairo_surface_destroy(M->bg);
	}
	for (i = 0; i < MAX_STATUS; i++) {
		cairo_destroy(sbar[i].ctx);
		cairo_surface_destroy(sbar[i].buf);
	}
	free(mons);
	return 0;
}

int get_mons(const char *bg, const char *cont) {
	/* get container counts */
	int i, j, n, *counts = NULL, ncounts;
	char *tok = NULL, *tmp = strdup(cont);
	tok = strtok(tmp," ");
	for (i = 0; tok; i++) {
		counts = realloc(counts, (i+1) * sizeof(int *));
		counts[i] = atoi(tok);
		tok = strtok(NULL," ");
	}
	free(tmp);
	counts = realloc(counts, (i+1) * sizeof(int *));
	counts[i] = -1;
	ncounts = i+1;
	/* get monitor geometries */
	mons = NULL;
	XineramaScreenInfo *geom = XineramaQueryScreens(dpy, &n);
	int minX = 0, minY = 0, maxX = 0, maxY = 0;
	for(i = 0; i < n; i++) {
		mons = realloc(mons, (i+1) * sizeof(Monitor));
		memset(&mons[i], 0, sizeof(Monitor));
		mons[i].x = geom[i].x_org;
		mons[i].y = geom[i].y_org;
		mons[i].w = geom[i].width;
		mons[i].h = geom[i].height;
		if (minX > mons[i].x) minX = mons[i].x;
		if (minY > mons[i].y) minY = mons[i].y;
		if (maxX < mons[i].x + mons[i].w) maxX = mons[i].x + mons[i].w;
		if (maxY < mons[i].y + mons[i].h) maxY = mons[i].y + mons[i].h;
	}
	/* create monitors and set background */
	cairo_surface_t *src, *dest;
	src = cairo_image_surface_create_from_png(bg);
	if (cairo_surface_status(src) != CAIRO_STATUS_SUCCESS) {
		src = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, maxX, maxY);
		cairo_t *blank = cairo_create(src);
		cairo_set_source_rgba(blank, 0, 0, 0, 1);
		cairo_paint(blank);
		cairo_destroy(blank);
	}
	int imgw = cairo_image_surface_get_width(src);
	int imgh = cairo_image_surface_get_height(src);
	Pixmap pix = XCreatePixmap(dpy, root, maxX-minX, maxY-minY,
			DefaultDepth(dpy,scr));
	dest = cairo_xlib_surface_create(dpy, pix, DefaultVisual(dpy,scr),
			maxX-minX, maxY-minY);
	cairo_t *ctx, *rctx;
	rctx = cairo_create(dest);
	Monitor *M;
	XWindowChanges wc;
	wc.stack_mode = Below;
	for(i = 0; i < n; i++) {
		M = &mons[i];
		if (i < n - 1) M->next = &mons[i+1];
		M->gap = conf.gap;
		M->split = conf.split;
		M->container = calloc(ncounts, sizeof(Container));
		M->focus = mons[i].container;
		M->mode = conf.mode;
		M->bg = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,M->w,M->h);
		M->margin = conf.margin;
		/* paint monitor bg */
		ctx = cairo_create(M->bg);
		cairo_scale(ctx, M->w / (float) imgw, M->h / (float) imgh);
		cairo_set_source_surface(ctx, src, 0, 0);
		cairo_paint(ctx);
		cairo_destroy(ctx);
		/* paint root pixmap */
		cairo_save(rctx);
		cairo_translate(rctx, M->x, M->y);
		cairo_scale(rctx, M->w / (float) imgw, M->h / (float) imgh);
		cairo_set_source_surface(rctx, src, 0, 0);
		cairo_paint(rctx);
		cairo_restore(rctx);
		Container *C;
		cairo_surface_t *t;
		for (j = 0; j < ncounts; j++) {
			C = &M->container[j];
			if (j < ncounts - 1) C->next = &M->container[j+1];
			C->n = counts[j];
			C->nn = C->n;
			C->bar = calloc(1, sizeof(Bar));
			C->bar->opts = conf.bar_opts;
			C->bar->w = M->w;
			C->bar->h = conf.bar_opts & BAR_HEIGHT;
			C->bar->buf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
					C->bar->w, C->bar->h);
			C->bar->ctx = cairo_create(C->bar->buf);
			cairo_set_font_face(C->bar->ctx, conf.font);
			cairo_set_font_size(C->bar->ctx, conf.font_size);
			C->win = XCreateSimpleWindow(dpy,root,0,0,M->w,C->bar->h,0,0,0);
			if (j == 0) wc.sibling = C->win;
			else XConfigureWindow(dpy, C->win, CWSibling | CWStackMode, &wc);
			XSelectInput(dpy, C->win, SELECT_EVENTS);
			t = cairo_xlib_surface_create(dpy, C->win,
					DefaultVisual(dpy,scr), M->w, C->bar->h);
			C->ctx = cairo_create(t);
			cairo_surface_destroy(t);
			XMapWindow(dpy, C->win);
		}
		M->tbar.buf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
				mons->w / 2, conf.bar_opts & BAR_HEIGHT);
		M->tbar.ctx = cairo_create(M->tbar.buf);
		M->tbar.h = conf.bar_opts & BAR_HEIGHT;
		cairo_set_font_face(M->tbar.ctx, conf.font);
		cairo_set_font_size(M->tbar.ctx, conf.font_size);
	}
	for (i = 0; i < MAX_STATUS; i++) {
		sbar[i].buf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
				mons->w / 2, conf.bar_opts & BAR_HEIGHT);
		sbar[i].ctx = cairo_create(sbar[i].buf);
		sbar[i].h = conf.bar_opts & BAR_HEIGHT;
		cairo_set_font_face(sbar[i].ctx, conf.font);
		cairo_set_font_size(sbar[i].ctx, conf.font_size);
	}
	cairo_surface_destroy(src);
	cairo_surface_destroy(dest);
	cairo_destroy(rctx);
	XSetWindowBackgroundPixmap(dpy, root, pix);
	XFreePixmap(dpy, pix);
	m = mons;
	free(counts);
	return 0;
}

#define MAX_LINE	256
int main_loop() {
	char line[MAX_LINE], *c;
	fd_set fds;
	int n, redraw, ret;
	int xfd = ConnectionNumber(dpy);
	int nfd = (conf.statfd > xfd ? conf.statfd : xfd) + 1;
	XEvent ev;
	while (running) {
		FD_ZERO(&fds);
		FD_SET(xfd, &fds);
		FD_SET(conf.statfd, &fds);
		select(nfd, &fds, 0, 0, NULL);
		if (conf.statfd && FD_ISSET(conf.statfd, &fds)) {
			fgets(line, MAX_LINE, conf.stat);
			redraw = sbar_parse(&sbar[(n=0)], (c=line));
			while ( (c=strchr(c, '&')) && (++n) < MAX_STATUS)
				redraw += sbar_parse(&sbar[n], (++c));
			if (redraw) tile();
			else draw_bars(True);
			XFlush(dpy);
		}
		if (FD_ISSET(xfd, &fds)) while (XPending(dpy)) {
			XNextEvent(dpy, &ev);
			if (ev.type < LASTEvent && handler[ev.type])
				handler[ev.type](&ev);
		}
	}
	return 0;
}

int purgatory(Window w) {
	XMoveWindow(dpy, w, purgX, purgY);
}

int set_focus() {
	Client *cc, *c = winmarks[1];
	if (!c) return 1;
	Window win; int rev;
	/* raise window */
	if (c->flags & WIN_FLOAT) {
		XWindowChanges wc;
		wc.stack_mode = Above;
		wc.sibling = m->container->win;
		XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
		for (cc = clients; cc; cc = cc->next) {
			if (cc->tags & m->tags && (cc->flags & WIN_FLOAT)) {
				wc.sibling = cc->win;
				XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
			}
		}
		wc.sibling = c->win;
		for (cc = clients; cc; cc = cc->next) {
			if (cc->parent == c->win)
				XConfigureWindow(dpy, cc->win, CWSibling | CWStackMode, &wc);
		}
	}
	else {
		XWindowChanges wc;
		wc.sibling = m->container->win;
		wc.stack_mode = Below;
		XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
	}
	/* set input focus */
	if (c->flags & WIN_FOCUS) send_message(c, WM_PROTOCOLS, WM_TAKE_FOCUS);
	else XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
	c->flags &= ~WIN_URGENT;
	return 0;
}

Client *wintoclient(Window w) {
	Client *c;
	for (c = clients; c; c = c->next)
		if (c->win == w) return c;
	return NULL;
}

int xerror(Display *d, XErrorEvent *e) {
	char msg[1024];
	XGetErrorText(d, e->error_code, msg, sizeof(msg));
	fprintf(stderr,"[X11 %d:%d] %s\n",
			e->request_code, e->error_code, msg);
}

int xlib_init(const char *theme_name) {
	/* INITS */
	if (!setlocale(LC_CTYPE,"")) die("unable to set locale");
	if (!XSupportsLocale()) die("unsupported locale");
	if (!XSetLocaleModifiers("")) die("unable to set locale modifiers");
	if (!(dpy=XOpenDisplay(0x0))) die("unable to open X display");
	if (FT_Init_FreeType(&ftlib)) die("unable to init freetype");
	/* GLOBALS */
	scr = DefaultScreen(dpy);
	root = DefaultRootWindow(dpy);
	XSetErrorHandler(xerror);
	XDefineCursor(dpy, root, XCreateFontCursor(dpy,68));
	gc = DefaultGC(dpy, scr);
	/* CONFIG */
	config_init(theme_name);
	Monitor *M;
	for (M = mons; M; M = M->next) {
		if (M->x + M->w > purgX) purgX = M->x + M->w + 10;
		if (M->y + M->h > purgY) purgY = M->y + M->h + 10;
	}
	XClearWindow(dpy,root);
	/* BINDING + GRABS */
	XSelectInput(dpy, root, SELECT_EVENTS);
	unsigned int mod[] = {0, LockMask, Mod2Mask, LockMask|Mod2Mask};
	KeyCode code;
	Key *key;
	XUngrabKey(dpy, AnyKey, AnyModifier, root);
	XSync(dpy,True);
	int i, j;
	for (i = 0; i < conf.nkeys; i++) {
		key = &conf.key[i];
		if ( (code=XKeysymToKeycode(dpy, key->keysym)) ) {
			for (j = 0; j < 4; j++)
				XGrabKey(dpy, code, key->mod|mod[j], root, True, GRABMODE);
		}
	}
	for (j = 0; j < 4; j++) {
		XGrabButton(dpy,1,Mod4Mask|mod[j],root,True,GRABMODE2);
		XGrabButton(dpy,2,Mod4Mask|mod[j],root,True,GRABMODE2);
		XGrabButton(dpy,3,Mod4Mask|mod[j],root,True,GRABMODE2);
	}
	memset(winmarks, 0, 10*sizeof(Client *));
	tile();
	XFlush(dpy);
	running = True;
	atoms_init();
	return 0;
}

int xlib_free() {
	Client *c;
	for (c = clients; c; c = c->next) killclient(c, NULL);
	XUngrabKey(dpy, AnyKey, AnyModifier, root);
	XUngrabButton(dpy, AnyButton, AnyModifier, root);
	XFlush(dpy);
	config_free();
	FT_Done_FreeType(ftlib);
	XCloseDisplay(dpy);
	return 0;
}

/**** LOCAL FUNCTIONS ****/

int apply_rules(Client *c) {
	XClassHint *hint = XAllocClassHint();
	XGetClassHint(dpy, c->win, hint);
	int i, m;
	const char *rc, *rn, *hc = hint->res_class, *hn = hint->res_name;
	for (i = 0; i < conf.nrules; i++) {
		rc = conf.rule[i].class;
		rn = conf.rule[i].name;
		m = 0;
		if (rc && hc && !strncmp(rc, hc, strlen(rc))) m++;
		if (rn && hn && !strncmp(rn, hn, strlen(rn))) m++;
		if ( (m && !(rc && rn)) || (m == 2) ) {
			if (conf.rule[i].tags > 0) c->tags = conf.rule[i].tags;
			c->flags |= conf.rule[i].flags;
		}
	}
	XFree(hint);
	return 0;
}

int get_hints(Client *c) {
	XWMHints *hint;
	if ( !(hint = XGetWMHints(dpy,c->win)) ) return;
	if (hint->flags & XUrgencyHint) c->flags |= WIN_URGENT;
	if (hint->flags & InputHint && !hint->input) c->flags |= WIN_FOCUS;
	if (hint->flags & (IconPixmapHint | IconMaskHint)) get_icon(c);
	XFree(hint);
	// TODO EWMH checks ??
	return 0;
}

int get_icon(Client *c) {
	XWMHints *hint;
	if (!(hint=XGetWMHints(dpy,c->win))) return;
	if (!(hint->flags & (IconPixmapHint | IconMaskHint))) return;
	if (c->icon) { cairo_surface_destroy(c->icon); c->icon = NULL; }
	int w, h, ig, sz = conf.font_size;
	Window wig;
	XGetGeometry(dpy, hint->icon_pixmap, &wig, &ig, &ig, &w, &h, &ig, &ig);
	if (c->icon) cairo_surface_destroy(c->icon);
	cairo_surface_t *icon, *mask = NULL;
	icon = cairo_xlib_surface_create(dpy, hint->icon_pixmap,
			DefaultVisual(dpy,scr), w, h);
	if (hint->flags & IconMaskHint)
	mask = cairo_xlib_surface_create_for_bitmap(dpy,
			hint->icon_mask, DefaultScreenOfDisplay(dpy), w, h);
	c->icon = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, sz, sz);
	cairo_t *ctx = cairo_create(c->icon);
	cairo_scale(ctx, sz / (double) w, sz / (double) h);
	cairo_set_source_surface(ctx, icon, 0, 0);
	if (mask) cairo_mask_surface(ctx, mask, 0, 0);
	else cairo_paint(ctx);
	cairo_destroy(ctx);
	cairo_surface_destroy(icon);
	if (mask) cairo_surface_destroy(mask);
	return 0;
}

int get_name(Client *c) {
	static const char *noname = "(no name)";
	Client *p;
	if (c->title && c->title != noname) XFree(c->title);
	if ( !(c->title=get_text(c,NET_WM_NAME)) )
		if ( !(c->title=get_text(c,WM_NAME)) )
			c->title = strdup(noname);
	return 0;
}

int get_size(Client *c) {
	long ret = 0;
	XSizeHints hint;
	if (!(XGetWMNormalHints(dpy,c->win,&hint,&ret))) return 0;
	if (hint.flags & PSize) {
		c->w = hint.width; c->h = hint.height;
	}
	if (hint.flags & PBaseSize) {
		c->w = hint.base_width; c->h = hint.base_height;
	}
	if (hint.flags & PMinSize) {
		if (c->w < hint.min_width) c->w = hint.min_width;
		if (c->h < hint.min_height) c->h = hint.min_height;
	}
	return 0;
}

/**** EVENT HANDLERS ****/

void buttonpress(XEvent *ev) {
	XButtonEvent *e = &ev->xbutton;
	Client *c;
	if ( !(c=wintoclient(e->subwindow)) ) return;
	if (c->flags & WIN_FLOAT) XRaiseWindow(dpy, c->win);
	if (c != winmarks[1]) {
		winmarks[0] = winmarks[1];
		winmarks[1] = c;
		tile();
	}
	int b = e->button;
	if (b > 3) return;
	c->flags &= ~WIN_FULL;
	if (b == 2) {
		tile();
		return;
	}
	XGrabPointer(dpy, root, True, PointerMotionMask | ButtonReleaseMask,
			GRABMODE, None, None, CurrentTime);
	XEvent ee;
	int dx, dy;
	int xx = e->x_root, yy = e->y_root;
	while (True) {
		expose(ev);
		XMaskEvent(dpy, PointerMotionMask | ButtonReleaseMask, &ee);
		if (ee.type == ButtonRelease) break;
		if (!(c->flags & WIN_FLOAT)) {
			c->flags |= WIN_FLOAT;
			tile();
			if (xx < c->x) c->x = xx;
			if (xx > c->x + c->w) c->x = xx - c->w;
			if (yy < c->y) c->y = yy;
			if (yy > c->y + c->h) c->y = yy - c->h;
		}
		XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
		dx = ee.xbutton.x_root - xx; xx = ee.xbutton.x_root;
		dy = ee.xbutton.y_root - yy; yy = ee.xbutton.y_root;
		if (b == 1) { c->x += dx; c->y += dy; }
		else if (b == 3) { c->w += dx; c->h += dy; }
	}
	XUngrabPointer(dpy, CurrentTime);
}

void configurerequest(XEvent *ev) {
	XConfigureRequestEvent *e = &ev->xconfigurerequest;
	Client *c;
	XWindowChanges wc;
	if ( (c=wintoclient(e->window)) ) {
		if (e->value_mask & CWX) c->x = e->x;
		if (e->value_mask & CWY) c->y = e->y;
		if (e->value_mask & CWWidth) c->w = e->width;
		if (e->value_mask & CWHeight) c->h = e->height;
		if (c->flags & WIN_FULL_TEST) {
			c->flags &= ~WIN_FULL;
			c->flags |= WIN_FLOAT;
		}
		if (c->w == m->w && c->h == m->h) c->flags |= WIN_FULL;
		/* Let gtk3 windows know we're listening: */
		XConfigureEvent cn;
		cn.type = ConfigureNotify; cn.display = dpy;
		cn.event = cn.window = c->win;
		cn.x = c->x; cn.y = c->y; cn.width = c->w; cn.height = c->h;
		cn.border_width = 0;
		cn.above = None;
		cn.override_redirect = False;
		XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&cn);
	}
	else {
		wc.x=e->x; wc.y=e->y; wc.width=e->width; wc.height=e->height;
		wc.sibling = e->above;
		wc.stack_mode = e->detail;
		wc.border_width = e->border_width;
		XConfigureWindow(dpy, e->window, e->value_mask, &wc);
	}
	tile();
}

void enternotify(XEvent *ev) {
	if (mons->next) {
		int x = ev->xcrossing.x_root;
		int y = ev->xcrossing.y_root;
		Monitor *M;
		for (M = mons; M; M = M->next) {
			if (M->x < x && M->x + M->w > x && M->y < y && M->y + M->h > y)
				m = M;
		}
	}
	if (!conf.focus_follow) return;
	Client *c = wintoclient(ev->xcrossing.window);
	if (!c) return;
	Container *C;
	for (C = m->container; C; C = C->next)
		if (C->top && C->top == c) m->focus = C;
	tile();
}

void expose(XEvent *ev) {
	Monitor *M; Container *C;
	for (M = mons; M; M = M->next) {
		for (C = M->container; C; C = C->next){
			cairo_set_source_surface(C->ctx, C->bar->buf, 0, 0);
			cairo_paint(C->ctx);
		}
	}
}

void keypress(XEvent *ev) {
	int i;
	XKeyEvent *e = &ev->xkey;
	KeySym sym = XkbKeycodeToKeysym(dpy, e->keycode, 0, 0);
	for (i = 0; i < conf.nkeys; i++) {
		if ( (sym==conf.key[i].keysym) && (conf.key[i].arg) &&
				conf.key[i].mod == ((e->state&~Mod2Mask)&~LockMask) ) {
			command(conf.key[i].arg);
		}
	}
}

void maprequest(XEvent *ev) {
	XMapRequestEvent *e = &ev->xmaprequest;
	XWindowAttributes wa;
	if (	!XGetWindowAttributes(dpy, e->window, &wa) ||
			wa.override_redirect ) return;
	Client *c;
	if ( (c=wintoclient(e->window)) ) return;
	c = calloc(1, sizeof(Client));
	c->win = e->window;
	get_hints(c);
	get_icon(c);
	get_name(c);
	apply_rules(c);
	if (!c->tags && !(c->tags=m->tags)) {
		Monitor *M;
		int i, tags = 0;
		for (M = mons; M; M = M->next) tags |= M->tags;
		for (i = 0; ((1<<i) & tags) && i < 9; i++);
		c->tags = m->tags = (1<<i);
	}
	if (XGetTransientForHint(dpy, c->win, &c->parent))
		c->flags |= WIN_TRANS;
	else
		c->parent = e->parent;
	c->x = wa.x; c->y = wa.y; c->w = wa.width; c->h = wa.height;
	if (c->w == m->w && c->h == m->h) c->flags |= WIN_FULL;
	XSelectInput(dpy, c->win, PropertyChangeMask | EnterWindowMask);
	Client *p;
	switch (conf.attach) {
		case ATTACH_TOP: c->next = clients; clients = c; break;
		case ATTACH_BOTTOM: push_client(c, NULL); break;
		case ATTACH_ABOVE: push_client(c, m->focus->top); break;
		case ATTACH_BELOW: push_client(c, m->focus->top->next); break;
	}
	winmarks[0] = winmarks[1];
	winmarks[1] = c;
	purgatory(c->win);
	XMapWindow(dpy, c->win);
	tile();
}

void propertynotify(XEvent *ev) {
	XPropertyEvent *e = &ev->xproperty;
	Client *c;
	if (e->window == root) {
		char *cmd;
		if (!XFetchName(dpy, root, &cmd)) return;
		if (strncmp("ALOPEX: ", cmd, 8) == 0) {
			XStoreName(dpy, root, "");
			command(cmd + 8);
		}
		if (cmd) XFree(cmd);
		return;
	}
	if ( !(c=wintoclient(e->window)) ) return;
	if (e->atom == XA_WM_NAME) get_name(c);
	else if (e->atom == XA_WM_HINTS) get_hints(c);
	else if (e->atom == XA_WM_CLASS) apply_rules(c);
	else if (e->atom == XA_WM_NORMAL_HINTS) get_size(c);
	// TODO:
	// icon ?
	// netWM
	// XA_TRANSIENT_FOR
	else return;
	tile();
}

void unmapnotify(XEvent *ev) {
	Client *c, *t;
	XUnmapEvent *e = &ev->xunmap;
	if (!(c=wintoclient(e->window))) return;
	winmarks[1] = winmarks[0];
	winmarks[0] = NULL;
	if (c == clients) clients = c->next;
	else {
		for (t = clients; t && t->next && t->next != c; t = t->next);
		t->next = c->next;
	}
	XFree(c->title);
	free(c); c = NULL;
	tile();
}

Added stat.

















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
#!/bin/bash
# ridiculously simple example status script
# for a better example written in C, see:
#   https://github.com/TrilbyWhite/junkdrawer/blob/master/lagopus.c

echo
sleep 10
while :; do echo "&& {i 11} $(date +%H:%M) &"; sleep 10; done

Deleted theme.h.

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
/* copyright J.McClure 2012-2013, see alopex.c or COPYING for details */

static const char colors[LASTColor][9] = {

#ifdef SummerCoat
#define THEME_NAME "SummerCoat"
	[Background]	= "#201814",
	[Default]		= "#686858",
	[Occupied]		= "#DDBB88",
	[Selected]		= "#EE8844",
	[Urgent]		= "#FFDD0E",
	[Title]			= "#EECCAA",
	[TabFocused]	= "#D0B072",
	[TabFocusedBG]	= "#242424",
	[TabTop]		= "#BB8844",
	[TabTopBG]		= "#242424",
	[TabDefault]	= "#686858",
	[TabDefaultBG]	= "#181818",
	[TagLine]		= "#FF4400",
#endif

#ifdef DayLight
#define THEME_NAME "DayLight"
	[Background]	= "#FAF0E6",
	[Default]		= "#121212",
	[Occupied]		= "#A04222",
	[Selected]		= "#CD6839",
	[Urgent]		= "#FF4222",
	[Title]			= "#B13E0F",
	[TabFocused]	= "#FF7216",
	[TabFocusedBG]	= "#EEE5DE",
	[TabTop]		= "#FF7216",
	[TabTopBG]		= "#EEE5DE",
	[TabDefault]	= "#A04222",
	[TabDefaultBG]	= "#CDC5BF",
	[TagLine]		= "#FF4400",
#endif

#ifdef WinterCoat 
#define THEME_NAME "WinterCoat"
	[Background]	= "#101010",
	[Default]		= "#686868",
	[Occupied]		= "#68A0DD",
	[Selected]		= "#BBE0EE",
	[Urgent]		= "#FF8880",
	[Title]			= "#DDDDDD",
	[TabFocused]	= "#68B0E0",
	[TabFocusedBG]	= "#242424",
	[TabTop]		= "#486488",
	[TabTopBG]		= "#242424",
	[TabDefault]	= "#686868",
	[TabDefaultBG]	= "#181818",
	[TagLine]		= "#2436AA",
#endif

};

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<