]> git.rmz.io Git - dotfiles.git/blob - awesome/widgets/awesompd/rcsample.lua
awesome: add awesompd widget + mpd bindings
[dotfiles.git] / awesome / widgets / awesompd / rcsample.lua
1 -- Standard awesome library
2 local gears = require("gears")
3 local awful = require("awful")
4 awful.rules = require("awful.rules")
5 require("awful.autofocus")
6 -- Widget and layout library
7 local wibox = require("wibox")
8 -- Theme handling library
9 local beautiful = require("beautiful")
10 -- Notification library
11 local naughty = require("naughty")
12 local menubar = require("menubar")
13
14 -- {{{ Error handling
15 -- Check if awesome encountered an error during startup and fell back to
16 -- another config (This code will only ever execute for the fallback config)
17 if awesome.startup_errors then
18 naughty.notify({ preset = naughty.config.presets.critical,
19 title = "Oops, there were errors during startup!",
20 text = awesome.startup_errors })
21 end
22
23 -- Handle runtime errors after startup
24 do
25 local in_error = false
26 awesome.connect_signal("debug::error", function (err)
27 -- Make sure we don't go into an endless error loop
28 if in_error then return end
29 in_error = true
30
31 naughty.notify({ preset = naughty.config.presets.critical,
32 title = "Oops, an error happened!",
33 text = err })
34 in_error = false
35 end)
36 end
37 -- }}}
38
39 -- {{{ Variable definitions
40 -- Themes define colours, icons, and wallpapers
41 beautiful.init("/usr/share/awesome/themes/default/theme.lua")
42
43 -- This is used later as the default terminal and editor to run.
44 terminal = "xterm"
45 editor = os.getenv("EDITOR") or "nano"
46 editor_cmd = terminal .. " -e " .. editor
47
48 -- Default modkey.
49 -- Usually, Mod4 is the key with a logo between Control and Alt.
50 -- If you do not like this or do not have such a key,
51 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
52 -- However, you can use another modifier like Mod1, but it may interact with others.
53 modkey = "Mod4"
54
55 -- Table of layouts to cover with awful.layout.inc, order matters.
56 local layouts =
57 {
58 awful.layout.suit.floating,
59 awful.layout.suit.tile,
60 awful.layout.suit.tile.left,
61 awful.layout.suit.tile.bottom,
62 awful.layout.suit.tile.top,
63 awful.layout.suit.fair,
64 awful.layout.suit.fair.horizontal,
65 awful.layout.suit.spiral,
66 awful.layout.suit.spiral.dwindle,
67 awful.layout.suit.max,
68 awful.layout.suit.max.fullscreen,
69 awful.layout.suit.magnifier
70 }
71 -- }}}
72
73 -- {{{ Wallpaper
74 if beautiful.wallpaper then
75 for s = 1, screen.count() do
76 gears.wallpaper.maximized(beautiful.wallpaper, s, true)
77 end
78 end
79 -- }}}
80
81 -- {{{ Tags
82 -- Define a tag table which hold all screen tags.
83 tags = {}
84 for s = 1, screen.count() do
85 -- Each screen has its own tag table.
86 tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
87 end
88 -- }}}
89
90 -- {{{ Menu
91 -- Create a laucher widget and a main menu
92 myawesomemenu = {
93 { "manual", terminal .. " -e man awesome" },
94 { "edit config", editor_cmd .. " " .. awesome.conffile },
95 { "restart", awesome.restart },
96 { "quit", awesome.quit }
97 }
98
99 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
100 { "open terminal", terminal }
101 }
102 })
103
104 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
105 menu = mymainmenu })
106
107 -- Menubar configuration
108 menubar.utils.terminal = terminal -- Set the terminal for applications that require it
109 -- }}}
110
111 -- {{{ Wibox
112 -- Create a textclock widget
113 mytextclock = awful.widget.textclock()
114
115 -- BEGIN OF AWESOMPD WIDGET DECLARATION
116
117 local awesompd = require('awesompd/awesompd')
118
119 musicwidget = awesompd:create() -- Create awesompd widget
120 musicwidget.font = "Liberation Mono" -- Set widget font
121 -- musicwidget.font_color = "#FFFFFF" --Set widget font color
122 -- musicwidget.background = "#000000" --Set widget background color
123 musicwidget.scrolling = true -- If true, the text in the widget will be scrolled
124 musicwidget.output_size = 30 -- Set the size of widget in symbols
125 musicwidget.update_interval = 10 -- Set the update interval in seconds
126
127 -- Set the folder where icons are located (change username to your login name)
128 musicwidget.path_to_icons = "/home/unlogic/.config/awesome/icons"
129
130 -- Set the path to the icon to be displayed on the widget itself
131 -- musicwidget.widget_icon = "/path/to/icon"
132
133 -- Set the default music format for Jamendo streams. You can change
134 -- this option on the fly in awesompd itself.
135 -- possible formats: awesompd.FORMAT_MP3, awesompd.FORMAT_OGG
136 musicwidget.jamendo_format = awesompd.FORMAT_MP3
137
138 -- Specify the browser you use so awesompd can open links from
139 -- Jamendo in it.
140 musicwidget.browser = "firefox"
141
142 -- If true, song notifications for Jamendo tracks and local tracks
143 -- will also contain album cover image.
144 musicwidget.show_album_cover = true
145
146 -- Specify how big in pixels should an album cover be. Maximum value
147 -- is 100.
148 musicwidget.album_cover_size = 50
149
150 -- This option is necessary if you want the album covers to be shown
151 -- for your local tracks.
152 musicwidget.mpd_config = "/home/unlogic/.mpdconf"
153
154 -- Specify decorators on the left and the right side of the
155 -- widget. Or just leave empty strings if you decorate the widget
156 -- from outside.
157 musicwidget.ldecorator = " "
158 musicwidget.rdecorator = " "
159
160 -- Set all the servers to work with (here can be any servers you use)
161 musicwidget.servers = {
162 { server = "localhost",
163 port = 6600 },
164 { server = "192.168.0.72",
165 port = 6600 }
166 }
167
168 -- Set the buttons of the widget. Keyboard keys are working in the
169 -- entire Awesome environment. Also look at the line 352.
170 musicwidget:register_buttons(
171 { { "", awesompd.MOUSE_LEFT, musicwidget:command_playpause() },
172 { "Control", awesompd.MOUSE_SCROLL_UP, musicwidget:command_prev_track() },
173 { "Control", awesompd.MOUSE_SCROLL_DOWN, musicwidget:command_next_track() },
174 { "", awesompd.MOUSE_SCROLL_UP, musicwidget:command_volume_up() },
175 { "", awesompd.MOUSE_SCROLL_DOWN, musicwidget:command_volume_down() },
176 { "", awesompd.MOUSE_RIGHT, musicwidget:command_show_menu() },
177 { "", "XF86AudioLowerVolume", musicwidget:command_volume_down() },
178 { "", "XF86AudioRaiseVolume", musicwidget:command_volume_up() },
179 { modkey, "Pause", musicwidget:command_playpause() } })
180
181 musicwidget:run() -- After all configuration is done, run the widget
182
183 -- END OF AWESOMPD WIDGET DECLARATION
184 -- Don't forget to add the widget to the wibox. It is done on the line 244.
185
186 -- Create a wibox for each screen and add it
187 mywibox = {}
188 mypromptbox = {}
189 mylayoutbox = {}
190 mytaglist = {}
191 mytaglist.buttons = awful.util.table.join(
192 awful.button({ }, 1, awful.tag.viewonly),
193 awful.button({ modkey }, 1, awful.client.movetotag),
194 awful.button({ }, 3, awful.tag.viewtoggle),
195 awful.button({ modkey }, 3, awful.client.toggletag),
196 awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
197 awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
198 )
199 mytasklist = {}
200 mytasklist.buttons = awful.util.table.join(
201 awful.button({ }, 1, function (c)
202 if c == client.focus then
203 c.minimized = true
204 else
205 -- Without this, the following
206 -- :isvisible() makes no sense
207 c.minimized = false
208 if not c:isvisible() then
209 awful.tag.viewonly(c:tags()[1])
210 end
211 -- This will also un-minimize
212 -- the client, if needed
213 client.focus = c
214 c:raise()
215 end
216 end),
217 awful.button({ }, 3, function ()
218 if instance then
219 instance:hide()
220 instance = nil
221 else
222 instance = awful.menu.clients({ width=250 })
223 end
224 end),
225 awful.button({ }, 4, function ()
226 awful.client.focus.byidx(1)
227 if client.focus then client.focus:raise() end
228 end),
229 awful.button({ }, 5, function ()
230 awful.client.focus.byidx(-1)
231 if client.focus then client.focus:raise() end
232 end))
233
234 for s = 1, screen.count() do
235 -- Create a promptbox for each screen
236 mypromptbox[s] = awful.widget.prompt()
237 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
238 -- We need one layoutbox per screen.
239 mylayoutbox[s] = awful.widget.layoutbox(s)
240 mylayoutbox[s]:buttons(awful.util.table.join(
241 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
242 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
243 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
244 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
245 -- Create a taglist widget
246 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
247
248 -- Create a tasklist widget
249 mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
250
251 -- Create the wibox
252 mywibox[s] = awful.wibox({ position = "top", screen = s })
253
254 -- Widgets that are aligned to the left
255 local left_layout = wibox.layout.fixed.horizontal()
256 left_layout:add(mylauncher)
257 left_layout:add(mytaglist[s])
258 left_layout:add(mypromptbox[s])
259
260 -- Widgets that are aligned to the right
261 local right_layout = wibox.layout.fixed.horizontal()
262 if s == 1 then right_layout:add(wibox.widget.systray()) end
263 right_layout:add(musicwidget.widget) -- Widget is added here.
264 right_layout:add(mytextclock)
265 right_layout:add(mylayoutbox[s])
266
267 -- Now bring it all together (with the tasklist in the middle)
268 local layout = wibox.layout.align.horizontal()
269 layout:set_left(left_layout)
270 layout:set_middle(mytasklist[s])
271 layout:set_right(right_layout)
272
273 mywibox[s]:set_widget(layout)
274 end
275 -- }}}
276
277 -- {{{ Mouse bindings
278 root.buttons(awful.util.table.join(
279 awful.button({ }, 3, function () mymainmenu:toggle() end),
280 awful.button({ }, 4, awful.tag.viewnext),
281 awful.button({ }, 5, awful.tag.viewprev)
282 ))
283 -- }}}
284
285 -- {{{ Key bindings
286 globalkeys = awful.util.table.join(
287 awful.key({ modkey, }, "Left", awful.tag.viewprev ),
288 awful.key({ modkey, }, "Right", awful.tag.viewnext ),
289 awful.key({ modkey, }, "Escape", awful.tag.history.restore),
290
291 awful.key({ modkey, }, "j",
292 function ()
293 awful.client.focus.byidx( 1)
294 if client.focus then client.focus:raise() end
295 end),
296 awful.key({ modkey, }, "k",
297 function ()
298 awful.client.focus.byidx(-1)
299 if client.focus then client.focus:raise() end
300 end),
301 awful.key({ modkey, }, "w", function () mymainmenu:show() end),
302
303 -- Layout manipulation
304 awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
305 awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
306 awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
307 awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
308 awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
309 awful.key({ modkey, }, "Tab",
310 function ()
311 awful.client.focus.history.previous()
312 if client.focus then
313 client.focus:raise()
314 end
315 end),
316
317 -- Standard program
318 awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
319 awful.key({ modkey, "Control" }, "r", awesome.restart),
320 awful.key({ modkey, "Shift" }, "q", awesome.quit),
321
322 awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
323 awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
324 awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
325 awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
326 awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
327 awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
328 awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
329 awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
330
331 awful.key({ modkey, "Control" }, "n", awful.client.restore),
332
333 -- Prompt
334 awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
335
336 awful.key({ modkey }, "x",
337 function ()
338 awful.prompt.run({ prompt = "Run Lua code: " },
339 mypromptbox[mouse.screen].widget,
340 awful.util.eval, nil,
341 awful.util.getdir("cache") .. "/history_eval")
342 end),
343 -- Menubar
344 awful.key({ modkey }, "p", function() menubar.show() end)
345 )
346
347 clientkeys = awful.util.table.join(
348 awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
349 awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
350 awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
351 awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
352 awful.key({ modkey, }, "o", awful.client.movetoscreen ),
353 awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
354 awful.key({ modkey, }, "n",
355 function (c)
356 -- The client currently has the input focus, so it cannot be
357 -- minimized, since minimized clients can't have the focus.
358 c.minimized = true
359 end),
360 awful.key({ modkey, }, "m",
361 function (c)
362 c.maximized_horizontal = not c.maximized_horizontal
363 c.maximized_vertical = not c.maximized_vertical
364 end)
365 )
366
367 -- Bind all key numbers to tags.
368 -- Be careful: we use keycodes to make it works on any keyboard layout.
369 -- This should map on the top row of your keyboard, usually 1 to 9.
370 for i = 1, 9 do
371 globalkeys = awful.util.table.join(globalkeys,
372 awful.key({ modkey }, "#" .. i + 9,
373 function ()
374 local screen = mouse.screen
375 local tag = awful.tag.gettags(screen)[i]
376 if tag then
377 awful.tag.viewonly(tag)
378 end
379 end),
380 awful.key({ modkey, "Control" }, "#" .. i + 9,
381 function ()
382 local screen = mouse.screen
383 local tag = awful.tag.gettags(screen)[i]
384 if tag then
385 awful.tag.viewtoggle(tag)
386 end
387 end),
388 awful.key({ modkey, "Shift" }, "#" .. i + 9,
389 function ()
390 local tag = awful.tag.gettags(client.focus.screen)[i]
391 if client.focus and tag then
392 awful.client.movetotag(tag)
393 end
394 end),
395 awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
396 function ()
397 local tag = awful.tag.gettags(client.focus.screen)[i]
398 if client.focus and tag then
399 awful.client.toggletag(tag)
400 end
401 end))
402 end
403
404 clientbuttons = awful.util.table.join(
405 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
406 awful.button({ modkey }, 1, awful.mouse.client.move),
407 awful.button({ modkey }, 3, awful.mouse.client.resize))
408
409 -- Set keys
410 -- Add this line before root.keys(globalkeys).
411 musicwidget:append_global_keys()
412
413 root.keys(globalkeys)
414 -- }}}
415
416 -- {{{ Rules
417 awful.rules.rules = {
418 -- All clients will match this rule.
419 { rule = { },
420 properties = { border_width = beautiful.border_width,
421 border_color = beautiful.border_normal,
422 focus = awful.client.focus.filter,
423 keys = clientkeys,
424 buttons = clientbuttons } },
425 { rule = { class = "MPlayer" },
426 properties = { floating = true } },
427 { rule = { class = "pinentry" },
428 properties = { floating = true } },
429 { rule = { class = "gimp" },
430 properties = { floating = true } },
431 -- Set Firefox to always map on tags number 2 of screen 1.
432 -- { rule = { class = "Firefox" },
433 -- properties = { tag = tags[1][2] } },
434 }
435 -- }}}
436
437 -- {{{ Signals
438 -- Signal function to execute when a new client appears.
439 client.connect_signal("manage", function (c, startup)
440 -- Enable sloppy focus
441 c:connect_signal("mouse::enter", function(c)
442 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
443 and awful.client.focus.filter(c) then
444 client.focus = c
445 end
446 end)
447
448 if not startup then
449 -- Set the windows at the slave,
450 -- i.e. put it at the end of others instead of setting it master.
451 -- awful.client.setslave(c)
452
453 -- Put windows in a smart way, only if they does not set an initial position.
454 if not c.size_hints.user_position and not c.size_hints.program_position then
455 awful.placement.no_overlap(c)
456 awful.placement.no_offscreen(c)
457 end
458 end
459
460 local titlebars_enabled = false
461 if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
462 -- buttons for the titlebar
463 local buttons = awful.util.table.join(
464 awful.button({ }, 1, function()
465 client.focus = c
466 c:raise()
467 awful.mouse.client.move(c)
468 end),
469 awful.button({ }, 3, function()
470 client.focus = c
471 c:raise()
472 awful.mouse.client.resize(c)
473 end)
474 )
475
476 -- Widgets that are aligned to the left
477 local left_layout = wibox.layout.fixed.horizontal()
478 left_layout:add(awful.titlebar.widget.iconwidget(c))
479 left_layout:buttons(buttons)
480
481 -- Widgets that are aligned to the right
482 local right_layout = wibox.layout.fixed.horizontal()
483 right_layout:add(awful.titlebar.widget.floatingbutton(c))
484 right_layout:add(awful.titlebar.widget.maximizedbutton(c))
485 right_layout:add(awful.titlebar.widget.stickybutton(c))
486 right_layout:add(awful.titlebar.widget.ontopbutton(c))
487 right_layout:add(awful.titlebar.widget.closebutton(c))
488
489 -- The title goes in the middle
490 local middle_layout = wibox.layout.flex.horizontal()
491 local title = awful.titlebar.widget.titlewidget(c)
492 title:set_align("center")
493 middle_layout:add(title)
494 middle_layout:buttons(buttons)
495
496 -- Now bring it all together
497 local layout = wibox.layout.align.horizontal()
498 layout:set_left(left_layout)
499 layout:set_right(right_layout)
500 layout:set_middle(middle_layout)
501
502 awful.titlebar(c):set_widget(layout)
503 end
504 end)
505
506 client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
507 client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
508 -- }}}