feat: add tint2ish tag list and clock to sidebar
This commit is contained in:
		
							
								
								
									
										52
									
								
								widget/clickable-container.fnl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								widget/clickable-container.fnl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| ;;; widget/clickable-container.fnl --- Clickable container | ||||
|  | ||||
| ;;; Commentary: | ||||
| ;; From https://github.com/PapyElGringo/material-awesome/blob/57116136a904560e8626b673370d2130b40dc62a/widgets/clickable-container.lua | ||||
|  | ||||
| ;;; Code: | ||||
|  | ||||
| (local wibox (require :wibox)) | ||||
| (local naughty (require :naughty)) | ||||
| (local awful (require :awful)) | ||||
|  | ||||
| ;;; | ||||
| ;; Functions | ||||
|  | ||||
| (fn build [widget] | ||||
|   (let [container (wibox.container.background widget)] | ||||
|     (var old-cursor {}) | ||||
|     (var old-wibox {}) | ||||
|  | ||||
|     (: container :connect_signal | ||||
|        :mouse::enter | ||||
|        (lambda [] | ||||
|          (let [cw _G.mouse.current_wibox] | ||||
|            (tset container :bg "#ffffff11") | ||||
|            ;; Hm, no idea how to get the wibox from this signal's arguments... | ||||
|            (when cw | ||||
|              (set old-cursor cw.cursor) | ||||
|              (set old-wibox cw) | ||||
|              (tset cw :cursor :hand1))))) | ||||
|  | ||||
|     (: container :connect_signal | ||||
|        :mouse::leave | ||||
|        (lambda [] | ||||
|          (tset container :bg "#ffffff00") | ||||
|          (when old-wibox | ||||
|            (tset old-wibox :cursor old-cursor) | ||||
|            (set old-wibox nil)))) | ||||
|  | ||||
|     (: container :connect_signal | ||||
|        :button::press | ||||
|        (lambda [] | ||||
|          (tset container :bg "#ffffff22"))) | ||||
|  | ||||
|     (: container :connect_signal | ||||
|        :button::release | ||||
|        (lambda [] | ||||
|          (tset container :bg "#ffffff11"))) | ||||
|  | ||||
|     container)) | ||||
|  | ||||
| build | ||||
| ;;; widget/clickable-container.fnl ends here | ||||
							
								
								
									
										80
									
								
								widget/list_update.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								widget/list_update.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,80 @@ | ||||
| local common = require("awful.widget.common") | ||||
| local dpi = require("beautiful").xresources.apply_dpi | ||||
| local wibox = require("wibox") | ||||
| local clickable_container = require("widget.clickable-container") | ||||
|  | ||||
| function list_update(w, buttons, label, data, objects) | ||||
|     -- update the widgets, creating them if needed | ||||
|     w:reset() | ||||
|     for i, o in ipairs(objects) do | ||||
|         local cache = data[o] | ||||
|         local ib, tb, bgb, tbm, ibm, l | ||||
|         if cache then | ||||
|             ib = cache.ib | ||||
|             tb = cache.tb | ||||
|             bgb = cache.bgb | ||||
|             tbm = cache.tbm | ||||
|             ibm = cache.ibm | ||||
|         else | ||||
|             ib = wibox.widget.imagebox() | ||||
|             tb = wibox.widget.textbox() | ||||
|             bgb = wibox.container.background() | ||||
|             tbm = wibox.container.margin(tb, dpi(4), dpi(4)) | ||||
|             ibm = wibox.container.margin(ib, dpi(10), dpi(8), dpi(8), dpi(8)) | ||||
|             -- ibm = wibox.container.margin(ib, dpi(4)) | ||||
|             l = wibox.layout.fixed.horizontal() | ||||
|             bg_clickable = clickable_container() | ||||
|  | ||||
|             -- All of this is added in a fixed widget | ||||
|             l:fill_space(true) | ||||
|             l:add(ibm) | ||||
|             -- l:add(tbm) | ||||
|             bg_clickable:set_widget(l) | ||||
|  | ||||
|             -- And all of this gets a background | ||||
|             -- bgb:set_widget(l) | ||||
|             bgb:set_widget(bg_clickable) | ||||
|  | ||||
|             bgb:buttons(common.create_buttons(buttons, o)) | ||||
|  | ||||
|             data[o] = { | ||||
|                 ib  = ib, | ||||
|                 tb  = tb, | ||||
|                 bgb = bgb, | ||||
|                 tbm = tbm, | ||||
|                 ibm = ibm, | ||||
|             } | ||||
|         end | ||||
|  | ||||
|         local text, bg, bg_image, icon, args = label(o, tb) | ||||
|         args = args or {} | ||||
|  | ||||
|         -- The text might be invalid, so use pcall. | ||||
|         if text == nil or text == "" then | ||||
|             tbm:set_margins(0) | ||||
|         else | ||||
|             if not tb:set_markup_silently(text) then | ||||
|                 tb:set_markup("<i><Invalid text></i>") | ||||
|             end | ||||
|         end | ||||
|         bgb:set_bg(bg) | ||||
|         if type(bg_image) == "function" then | ||||
|             -- TODO: Why does this pass nil as an argument? | ||||
|             bg_image = bg_image(tb,o,nil,objects,i) | ||||
|         end | ||||
|         bgb:set_bgimage(bg_image) | ||||
|         if icon then | ||||
|             ib:set_image(icon) | ||||
|         else | ||||
|             ibm:set_margins(0) | ||||
|         end | ||||
|  | ||||
|         bgb.shape              = args.shape | ||||
|         bgb.shape_border_width = args.shape_border_width | ||||
|         bgb.shape_border_color = args.shape_border_color | ||||
|  | ||||
|         w:add(bgb) | ||||
|    end | ||||
| end | ||||
|  | ||||
| return list_update | ||||
| @@ -5,17 +5,101 @@ | ||||
| (local awful (require :awful)) | ||||
| (local beautiful (require :beautiful)) | ||||
| (local wibox (require :wibox)) | ||||
| (local common (require :awful.widget.common)) | ||||
| (local dpi (. (require :beautiful) :xresources :apply_dpi)) | ||||
|  | ||||
| (local std (require :lib.std)) | ||||
|  | ||||
| ;;; | ||||
| ;; Functions | ||||
|  | ||||
| (fn update-tag-list [w buttons label data objects] | ||||
|   (: w :reset) | ||||
|   (each [i o (ipairs objects)] | ||||
|     (let [cache (. data o)] | ||||
|       (var ib nil) | ||||
|       (var tb nil) | ||||
|       (var bgb nil) | ||||
|       (var tbm nil) | ||||
|       (var ibm nil) | ||||
|       (var l nil) | ||||
|       (if cache | ||||
|           (do | ||||
|             (set ib cache.ib) | ||||
|             (set tb cache.tb) | ||||
|             (set bgb cache.bgb) | ||||
|             (set tbm cache.tbm) | ||||
|             (set ibm cache.ibm)) | ||||
|           (do | ||||
|             (set ib (wibox.widget.imagebox)) | ||||
|             (set tb (wibox.widget.textbox)) | ||||
|             (set bgb (wibox.container.background)) | ||||
|             (set tbm (wibox.container.margin tb (dpi 4) (dpi 4))) | ||||
|             ;; (set ibm (wibox.container.margin ib (dpi 12) (dpi 12) (dpi 12) (dpi 12))) | ||||
|             (set ibm (wibox.container.margin ib (dpi 4))) | ||||
|             (set l (wibox.layout.fixed.horizontal)) | ||||
|  | ||||
|             ;; All of this is added in a fixed widget | ||||
|             (doto l | ||||
|               (: :fill_space true) | ||||
|               (: :add ibm) | ||||
|               (: :add tbm)) | ||||
|  | ||||
|             ;; And all of this gets a background | ||||
|             (: bgb :set_widget l) | ||||
|  | ||||
|             (: bgb :buttons (common.create_buttons buttons o)) | ||||
|  | ||||
|             (tset data o {:ib ib :tb tb :bgb bgb :tbm tbm :ibm ibm}))) | ||||
|  | ||||
|       (let [[text bg bg-image icon args] (label o tb)] | ||||
|         ;; The text might be invalid, so use pcall. | ||||
|         (if (std.s-empty? text) | ||||
|             (: tbm :set_margins 0) | ||||
|             (when (not (: tb :set_markup_silently text)) | ||||
|               (: tb :set_markup "<i><Invalid text></i>"))) | ||||
|         (: bgb :set_bg bg) | ||||
|  | ||||
|         (: bgb :set_bgimage (if (std.fn? bg-image) | ||||
|                                 ;; TODO: Why does this pass nil as an argument? | ||||
|                                 (bg-image tb o nil objects i) | ||||
|                                 bg-image)) | ||||
|  | ||||
|         (if icon | ||||
|             (: ib :set_image icon) | ||||
|             (: ibm :set_margins 0)) | ||||
|  | ||||
|         (let [args (or args {})] | ||||
|          (doto bgb | ||||
|            (tset :shape args.shape) | ||||
|            (tset :shape_border_width args.shape_border_width) | ||||
|            (tset :shape_border_color args.shape_border_color))) | ||||
|  | ||||
|         (: w :add bgb))))) | ||||
|  | ||||
| (fn container [] | ||||
|   (let [l (wibox.layout.fixed.vertical)] | ||||
|     ;; Wishlist: let* | ||||
|     (local innerm (wibox.container.margin nil 10 10)) | ||||
|     (local bg (wibox.container.background innerm "#faa")) | ||||
|     (local outerm (wibox.container.margin bg 4 4)) | ||||
|  | ||||
|     (: l :fill_space true) | ||||
|     (: l :add outerm) | ||||
|  | ||||
|     l)) | ||||
|  | ||||
| (fn tag-list [s] | ||||
|   (awful.widget.taglist | ||||
|    s | ||||
|    awful.widget.taglist.filter.selected | ||||
|    awful.widget.taglist.filter.all | ||||
|    {} | ||||
|    {:font (.. beautiful.font " Bold 10")} | ||||
|    nil | ||||
|    {:font (.. beautiful.font " Bold 10") | ||||
|     :spacing 2} | ||||
|    ;; update-tag-list | ||||
|    (require :widget.list_update) | ||||
|    ;; awful.widget.common.list_update | ||||
|    ;; (container) | ||||
|    (wibox.layout.fixed.vertical) | ||||
|    )) | ||||
|  | ||||
|   | ||||
							
								
								
									
										43
									
								
								widget/textclock.fnl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								widget/textclock.fnl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| ;;; widget/textclock.fnl --- Configurable text clock widget | ||||
|  | ||||
| ;;; Commentary: | ||||
| ;; More modular than the standard library | ||||
|  | ||||
| ;;; Code: | ||||
|  | ||||
| (local beautiful (require :beautiful)) | ||||
| (local gears (require :gears)) | ||||
| (local glib (. (require :lgi) :GLib)) | ||||
| (local wibox (require :wibox)) | ||||
| (local DateTime glib.DateTime) | ||||
| (local TimeZone glib.TimeZone) | ||||
|  | ||||
| ;;; | ||||
| ;; Functions | ||||
|  | ||||
| (fn calc-timeout [real-timeout] | ||||
|   (% (- real-timeout (os.time)) real-timeout)) | ||||
|  | ||||
| (fn textclock [format timeout timezone font] | ||||
|   (let [format (or format " %a %b %d, %H:%M ") | ||||
|         timeout (or timeout 60) | ||||
|         timezone (or (and timezone (TimeZone.new timezone)) | ||||
|                      (TimeZone.new_local)) | ||||
|         font (or font beautiful.textclock_font) | ||||
|         w (wibox.widget.textbox)] | ||||
|     (var t nil) | ||||
|  | ||||
|     (tset w :font font) | ||||
|  | ||||
|     (fn w._private.textclock_update_cb [] | ||||
|       (: w :set_markup (: (DateTime.new_now timezone) :format format)) | ||||
|       (tset t :timeout (calc-timeout timeout)) | ||||
|       (: t :again) | ||||
|       true) | ||||
|  | ||||
|     (set t (gears.timer.weak_start_new timeout w._private.textclock_update_cb)) | ||||
|     (: t :emit_signal :timeout) | ||||
|     w)) | ||||
|  | ||||
| textclock | ||||
| ;;; widget/textclock.fnl ends here | ||||
		Reference in New Issue
	
	Block a user