(local fun (require :lib.fun))

(local awful (require :awful))
(require :awful.autofocus)
(local beautiful (require :beautiful))

;; HACK Use xfce4-notifyd for dbus integration.
;; Purely for pa-applet until a better solution is found.
(local _dbus dbus)
(set _G.dbus nil)
(local naughty (require :naughty))
(set _G.dbus _dbus)

(beautiful.init (require :theme))

(require :module.decorate)
(require :module.sidebar)
(require :module.autostart)

(require :conf.client)
(require :conf.tags)
(_G.root.keys (require :conf.keys))

;; TEMP Next release should support this through `beautiful'.
(set naughty.config.defaults.border_width beautiful.notification_border_width)
(set naughty.config.defaults.icon_size beautiful.notification_icon_size)

(tset awful.util :terminal (. (require :conf.apps) :terminal))

;;;
;; Post-config -- wiring it all up

(->> {:manage (lambda [c] nil
                (when (and awesome.startup
                           (not c.size_hints.user_position)
                           (not c.size_hints.program_position))
                  ;; Prevent clients from being unreachable after screen count changes.
                  (awful.placement.no_offscreen c)))
      :mouse::enter (lambda [c]
                      (when (and (~= (awful.layout.get c.screen)
                                     awful.layout.suit.magnifier)
                                 (awful.client.focus.filter c))
                        (set client.focus c)))
      :focus (lambda [c] (set c.border_color beautiful.border_focus))
      :unfocus (lambda [c] (set c.border_color beautiful.border_normal))}
     (fun.each (fn [event callback] (client.connect_signal event callback))))

{}