~cmpitg/cmpitg-awesome-lua/trunk

« back to all changes in this revision

Viewing changes to tim_tags_config.lua

  • Committer: Dương "Yang" ヤン Hà Nguyễn
  • Date: 2012-01-29 17:28:40 UTC
  • Revision ID: cmpitg@gmail.com-20120129172840-dg5843ddzetnnsfx
Polish a bit, reduce tags, add screen #2, change keymaps

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
-- Custom functions
3
3
--
4
4
 
 
5
function getTagsAbbr(tag_names)
 
6
   local ret = {}
 
7
   for idx = 1, #tag_names do
 
8
      ret[idx] = string.lower(string.sub(tag_names[idx], 1, 1))
 
9
   end
 
10
   return ret
 
11
end
 
12
 
 
13
function giveFocus(c)
 
14
   c.screen = mouse.screen -- dirty fix for strange screen changing behaviour
 
15
   client.focus = c
 
16
   c:raise()
 
17
end
 
18
 
 
19
function showNotification(title, msg)
 
20
   naughty.notify({ text = msg,
 
21
                    title = title,
 
22
                    fg = "#ffggcc",
 
23
                    bg = "#bbggcc",
 
24
                    ontop = false,
 
25
                    timeout = 1
 
26
                 })
 
27
end
 
28
 
5
29
function tim_table_indexOf(table, item)
6
30
   table = table or {}
7
31
   for i = 1, #table do
8
 
      if table[i] == item then
 
32
      if string.find(string.lower(table[i]), item) then
9
33
         return i
10
34
      end
11
35
   end
13
37
end
14
38
 
15
39
function tim_findTag(name)
16
 
   return tim_table_indexOf(timTagsInitial, name)
 
40
   return tim_table_indexOf(tags.settings[mouse.screen].names, name)
17
41
end
18
42
 
19
43
-- Switch to tag
33
57
          end
34
58
end
35
59
-- Move client to tag
36
 
function timMoveClientToTag(tag)
 
60
function timMoveClientToTag(screen, tag)
37
61
   return function (c)
38
 
             if client.focus and tags[client.focus.screen][tag] then
39
 
                awful.client.movetotag(tags[client.focus.screen][tag])
 
62
             if client.focus and tags[screen][tag] then
 
63
                awful.client.movetotag(tags[screen][tag])
40
64
             end
41
65
          end
42
66
end
43
67
-- Toggle tag for a client
44
 
function timToggleTag(tag)
 
68
function timToggleTag(screen, tag)
45
69
   return function (c)
46
 
             if client.focus and tags[client.focus.screen][tag] then
47
 
                awful.client.toggletag(tags[client.focus.screen][tag])
 
70
             if client.focus and tags[screen][tag] then
 
71
                awful.client.toggletag(tags[screen][tag])
48
72
             end
49
73
          end
50
74
end
70
94
 
71
95
layouts = {
72
96
   awful.layout.suit.floating,
73
 
   awful.layout.suit.magnifier,
74
97
   awful.layout.suit.tile,
75
 
   awful.layout.suit.tile.left,
76
98
   awful.layout.suit.tile.bottom,
77
 
   awful.layout.suit.tile.top,
78
 
   awful.layout.suit.fair,
79
 
   awful.layout.suit.fair.horizontal,
80
 
   awful.layout.suit.spiral,
81
 
   awful.layout.suit.spiral.dwindle,
82
 
   awful.layout.suit.max,
83
 
   awful.layout.suit.max.fullscreen
84
 
}
85
 
 
86
 
timTagsInitial = { "m", "e", "p", "w", "o",
87
 
                   "i", "a", "c", "b", "g",
88
 
                   "r", "s", "t" }
 
99
   awful.layout.suit.magnifier,
 
100
   awful.layout.suit.max.fullscreen,
 
101
   awful.layout.suit.max
 
102
}
 
103
 
 
104
-- {{{ My custom tags
 
105
--
 
106
 
 
107
-- For screen 1
 
108
 
 
109
-- tags_screen1 = {
 
110
--    "m", "c", "w", "o",
 
111
--    "b", "i", "f", "t"
 
112
-- }
 
113
 
 
114
tags_screen1 = {
 
115
   "Main", "Console", "WWW", "Other",
 
116
   "Browser", "IM", "Floating", "Temp"
 
117
}
 
118
 
 
119
 
 
120
layouts_screen1 = {
 
121
   layouts[2],  layouts[6],  layouts[1], layouts[1],
 
122
   layouts[1],  layouts[1],  layouts[1], layouts[1]
 
123
}
 
124
 
 
125
-- For screen 2
 
126
 
 
127
tags_screen2 = { "Main", "Read", "WWW", "Other" }
 
128
 
 
129
layouts_screen2 = {
 
130
   layouts[1], layouts[1], layouts[1], layouts[1]
 
131
}
 
132
 
 
133
--- }}}
89
134
 
90
135
-- {{{ Tags
91
136
-- Define a tag table which hold all screen tags.
92
137
 
 
138
tags = {}
 
139
 
93
140
tags = {
94
 
   -- names = { "main", "www", "office", "im", "background", "coding",
95
 
   --        "browser", "graphics", "tmp" },
96
 
   names = timTagsInitial,
97
 
   layout = { layouts[3], layouts[2], layouts[2],
98
 
              layouts[11], layouts[2], layouts[1],
99
 
              layouts[1], layouts[11], layouts[11],
100
 
              layouts[2],  layouts[3], layouts[3],
101
 
              layouts[1]
102
 
           }
 
141
   settings = {
 
142
      {
 
143
         names = tags_screen1,
 
144
         layout = layouts_screen1
 
145
      },
 
146
      {
 
147
         names = tags_screen2,
 
148
         layout = layouts_screen2
 
149
      }
 
150
   }
103
151
}
104
152
 
105
153
-- Create tags for all screens
 
154
-- -- Tag table for screen 1
 
155
-- tags[1] = awful.tag(tags.names, 1, tags.layout)
 
156
-- -- Tag table for screen 2
 
157
-- tags[2] = awful.tag(tags)
 
158
 
106
159
for s = 1, screen.count() do
107
 
   -- Each screen has its own tag table
108
 
   tags[s] = awful.tag(tags.names, s, tags.layout)
 
160
   tags[s] = awful.tag(tags.settings[s].names,
 
161
                       s,
 
162
                       tags.settings[s].layout)
109
163
end
 
164
 
110
165
-- }}}
111
166
 
112
167
-- Key bindings
113
168
--
 
169
-- Modal mode for tags keybinding
 
170
--
 
171
 
 
172
modaltagkeys = {}
 
173
 
 
174
modaltagkeys = {
 
175
   -- Switch to tagw
 
176
   m = function(screen_num, c) timTagViewOnly(screen_num, 1)(c) end,
 
177
   c = function(screen_num, c) timTagViewOnly(screen_num, 2)(c) end,
 
178
   w = function(screen_num, c) timTagViewOnly(screen_num, 3)(c) end,
 
179
   o = function(screen_num, c) timTagViewOnly(screen_num, 4)(c) end,
 
180
   b = function(screen_num, c) timTagViewOnly(screen_num, 5)(c) end,
 
181
   i = function(screen_num, c) timTagViewOnly(screen_num, 6)(c) end,
 
182
   f = function(screen_num, c) timTagViewOnly(screen_num, 7)(c) end,
 
183
   t = function(screen_num, c) timTagViewOnly(screen_num, 8)(c) end,
 
184
 
 
185
   -- Toggle tags
 
186
   M = function(screen_num, c) timTagViewToggle(screen_num, 1)(c) end,
 
187
   C = function(screen_num, c) timTagViewToggle(screen_num, 2)(c) end,
 
188
   W = function(screen_num, c) timTagViewToggle(screen_num, 3)(c) end,
 
189
   O = function(screen_num, c) timTagViewToggle(screen_num, 4)(c) end,
 
190
   B = function(screen_num, c) timTagViewToggle(screen_num, 5)(c) end,
 
191
   I = function(screen_num, c) timTagViewToggle(screen_num, 6)(c) end,
 
192
   F = function(screen_num, c) timTagViewToggle(screen_num, 7)(c) end,
 
193
   T = function(screen_num, c) timTagViewToggle(screen_num, 8)(c) end
 
194
}
 
195
 
114
196
-- Bind all key numbers to tags.
115
197
--
116
198
 
117
199
globalkeys = globalkeys or { }
118
200
 
119
 
for i = 1, #timTagsInitial do
120
 
   globalkeys = awful.util.table.join(
121
 
      globalkeys,
122
 
      -- Switch to tag
123
 
      awful.key({ modkey, "Mod1" }, timTagsInitial[i],
124
 
                timTagViewOnly(mouse.screen, i)),
125
 
      -- View tag
126
 
      awful.key({ modkey, "Shift" }, timTagsInitial[i],
127
 
                timTagViewToggle(mouse.screen, i)),
128
 
      -- Move to tag
129
 
      awful.key({ modkey, "Shift", "Mod1" }, timTagsInitial[i],
130
 
                timMoveClientToTag(i)),
131
 
      -- Toggle tag-name for the client
132
 
      awful.key({ modkey, "Shift", "Control", "Mod1" }, timTagsInitial[i],
133
 
                timToggleTag(i))
134
 
   )
 
201
-- Bind the modal mode
 
202
globalkeys = awful.util.table.join(
 
203
   globalkeys,
 
204
   awful.key({ modkey, "Control" }, "space",
 
205
             -- {{{ Modal mode
 
206
             function (c)
 
207
                keygrabber.run(
 
208
                   function (mod, key, event)
 
209
                      if string.find(key, "Super") then
 
210
                         showNotification("Modal mode",
 
211
                                          "Waiting for the next key...")
 
212
                      end
 
213
 
 
214
                      if event == "release" then
 
215
                         return true
 
216
                      end
 
217
 
 
218
                      if not string.find(key, "Shift") then
 
219
                         keygrabber.stop()
 
220
                      end
 
221
 
 
222
                      if modaltagkeys[key] then
 
223
                         modaltagkeys[key](mouse.screen, c)
 
224
                      end
 
225
                      return true
 
226
                   end)
 
227
             end
 
228
             -- }}}
 
229
          )
 
230
)
 
231
 
 
232
for screen_idx = 1, screen.count() do
 
233
   local tag_names = getTagsAbbr(tags.settings[screen_idx].names)
 
234
   for i = 1, #tag_names do
 
235
      globalkeys = awful.util.table.join(
 
236
         globalkeys,
 
237
         -- View tag
 
238
         awful.key({ modkey, "Shift" }, tag_names[i],
 
239
                   timTagViewToggle(screen_idx, i)),
 
240
         -- Move to tag
 
241
         awful.key({ modkey, "Shift", "Mod1" }, tag_names[i],
 
242
                   timMoveClientToTag(screen_idx, i)),
 
243
         -- Toggle tag-name for the client
 
244
         awful.key({ modkey, "Shift", "Control", "Mod1" }, tag_names[i],
 
245
                   timToggleTag(screen_idx, i))
 
246
      )
 
247
   end
135
248
end
136
249
 
137
250
--
141
253
 
142
254
clientkeys = clientkeys or {}
143
255
clientkeys = awful.util.table.join(
 
256
   -- Titlebar
 
257
   awful.key( { modkey }, ",",
 
258
              function (c)
 
259
                 if c.titlebar then
 
260
                    awful.titlebar.remove(c)
 
261
                    debug_notify(c.name .. "\ntitlebar " .. colored_off)
 
262
                 else
 
263
                    awful.titlebar.add(c, { altkey = "Mod1" })
 
264
                    debug_notify(c.name .. "\ntitlebar " .. colored_on)
 
265
                 end
 
266
              end),
144
267
   -- Fullscreen
145
 
   awful.key({ modkey,           }, "f",
146
 
             function (c) c.fullscreen = not c.fullscreen  end),
 
268
   awful.key({ modkey           }, "f",
 
269
             function (c)
 
270
                c.screen = mouse.screen
 
271
                c.fullscreen = not c.fullscreen
 
272
             end),
147
273
   -- Kill
148
274
   awful.key({ modkey            }, "x",
149
275
             function (c) c:kill()                         end),
150
276
   -- Toggle floating
151
 
   awful.key({ modkey, "Control" }, "space",
 
277
   awful.key({ modkey, "Control", "Mod1" }, "space",
152
278
             awful.client.floating.toggle                     ),
153
279
   -- Swap with masters
154
 
   awful.key({ modkey,           }, "Return",
 
280
   awful.key({ modkey, "Shift"   }, "Return",
155
281
             function (c) c:swap(awful.client.getmaster()) end),
156
282
   -- Move to screen
157
283
   awful.key({ modkey,           }, "o",
165
291
   -- Toggle maximize
166
292
   awful.key({ modkey,           }, "m",
167
293
             function (c)
 
294
                c.screen = mouse.screen
168
295
                c.maximized_horizontal = not c.maximized_horizontal
169
296
                c.maximized_vertical   = not c.maximized_vertical
170
297
             end),
171
298
   -- Bigger
172
299
   awful.key({ modkey, }, "End",
173
300
             function ()
174
 
                awful.client.moveresize(0, 0, 20, 20)
 
301
                awful.client.moveresize(0, 0, 0, 20)
175
302
             end),
176
303
   -- Smaller
177
304
   awful.key({ modkey, }, "Home",
178
305
             function ()
179
 
                awful.client.moveresize(0, 0, -20, -20)
 
306
                awful.client.moveresize(0, 0, 0, -20)
 
307
             end),
 
308
   --
 
309
   awful.key({ modkey, }, "Prior",
 
310
             function ()
 
311
                awful.client.moveresize(0, 0, -20, 0)
 
312
             end),
 
313
   --
 
314
   awful.key({ modkey, }, "Next",
 
315
             function ()
 
316
                awful.client.moveresize(0, 0, 20, 0)
180
317
             end),
181
318
   -- Increase transparency
182
319
   awful.key({ modkey, "Mod1", "Shift" }, "Down",
218
355
                local tmp = tim_centralize(c)
219
356
                c:geometry({ x = tmp.new_x, y = tmp.new_y,
220
357
                             width = tmp.new_width, height = tmp.new_height })
221
 
                -- awful.client.property.set(c, "geometry", { width=800, height=600 })
 
358
                giveFocus(c)
 
359
             end),
 
360
   awful.key({ modkey, "Control"          }, "t",
 
361
             function (c)
 
362
                local tmp = tim_halfmaxwidth(c)
 
363
                c:geometry({ x = tmp.new_x, y = tmp.new_y,
 
364
                             width = tmp.new_width, height = tmp.new_height })
 
365
                giveFocus(c)
 
366
             end),
 
367
   awful.key({ modkey, "Control"          }, "n",
 
368
             function (c)
 
369
                local tmp = tim_halfmaxheight(c)
 
370
                c:geometry({ x = tmp.new_x, y = tmp.new_y,
 
371
                             width = tmp.new_width, height = tmp.new_height })
 
372
                giveFocus(c)
 
373
             end),
 
374
   awful.key({ modkey, "Control"          }, "Left",
 
375
             function (c)
 
376
                local tmp = tim_leftfull(c)
 
377
                c:geometry({ x = tmp.new_x, y = tmp.new_y,
 
378
                             width = tmp.new_width, height = tmp.new_height })
 
379
                giveFocus(c)
 
380
             end),
 
381
   awful.key({ modkey, "Control"          }, "Right",
 
382
             function (c)
 
383
                local tmp = tim_rightfull(c)
 
384
                c:geometry({ x = tmp.new_x, y = tmp.new_y,
 
385
                             width = tmp.new_width, height = tmp.new_height })
 
386
                giveFocus(c)
222
387
             end)
223
388
 
224
389
)
243
408
     properties = { floating = true } },
244
409
   { rule = { class = "Gimp" },
245
410
     properties = { floating = true,
246
 
                    tag = tags[mouse.screen][tim_findTag("g")] } },
 
411
                    tag = tags[mouse.screen][tim_findTag("f")] } },
 
412
   { rule = { class = "Xsane" },
 
413
     properties = { floating = true } },
 
414
   { rule = { class = "Inferno" },
 
415
     properties = { floating = true } },
247
416
   { rule = { class = "Cinelerra" },
248
417
     properties = { floating = true,
249
 
                    tag = tags[mouse.screen][tim_findTag("g")] } },
 
418
                    tag = tags[mouse.screen][tim_findTag("f")] } },
250
419
   -- { rule = { class = "Audacity" },
251
420
   --   properties = { floating = true,
252
421
   --                  tag = tags[mouse.screen][5] } },
258
427
   -- Set Firefox to always map on tags number 2 of screen 1.
259
428
   { rule = { class = "Firefox" },
260
429
     properties = { tag = tags[mouse.screen][tim_findTag("w")] } },
261
 
   { rule = { class = "Chromium" },
 
430
   { rule = { class = "Chrome" },
262
431
     properties = { tag = tags[mouse.screen][tim_findTag("w")] } },
263
432
   { rule = { class = "Seamonkey" },
264
433
     properties = { tag = tags[mouse.screen][tim_findTag("w")] } },
270
439
     properties = { tag = tags[mouse.screen][tim_findTag("i")] } },
271
440
   { rule = { class = "Skype" },
272
441
     properties = { tag = tags[mouse.screen][tim_findTag("i")] } },
273
 
   { rule = { class = "Kdenlive" },
274
 
     properties = { tag = tags[mouse.screen][tim_findTag("g")] } },
275
 
   { rule = { class = "Vuze" },
276
 
     properties = { tag = tags[mouse.screen][tim_findTag("t")] } },
277
 
   { rule = { class = "Nautilus" },
278
 
     properties = { tag = tags[mouse.screen][tim_findTag("b")] } },
279
 
   { rule = { class = "Krusader" },
280
 
     properties = { tag = tags[mouse.screen][tim_findTag("b")] } },
 
442
   -- { rule = { class = "Nautilus" },
 
443
   --   properties = { tag = tags[mouse.screen][tim_findTag("b")] } },
281
444
   { rule = { class = "emelFM2" },
282
445
     properties = { tag = tags[mouse.screen][tim_findTag("b")] } }
283
446
}