summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Makhov <pmakhov@theoctavegroup.com>2019-11-14 22:23:43 -0500
committerPavel Makhov <pmakhov@theoctavegroup.com>2019-11-14 22:23:43 -0500
commit63d3c3dd1dfc3d435f4807f69666674b00dc6bd3 (patch)
tree2246f2ba3fe7547adef43d2e7638f173bf6f1281
parent85ed393e634fb76daf141ec87b92181b1b8e3316 (diff)
Add stackoverflow widget
-rw-r--r--stackoverflow-widget/README.md46
-rw-r--r--stackoverflow-widget/screenshot.pngbin0 -> 41268 bytes
-rw-r--r--stackoverflow-widget/so-icon.svg1
-rw-r--r--stackoverflow-widget/stackoverflow.lua123
4 files changed, 170 insertions, 0 deletions
diff --git a/stackoverflow-widget/README.md b/stackoverflow-widget/README.md
new file mode 100644
index 0000000..c906bf1
--- /dev/null
+++ b/stackoverflow-widget/README.md
@@ -0,0 +1,46 @@
+# Stackoverflow widget
+
+When clicked, widget shows latest questions from stackoverflow.com with a given tag(s).
+
+![screenshot](./screenshot.png)
+
+## Customization
+
+It is possible to customize widget by providing a table with all or some of the following config parameters:
+
+| Name | Default | Description |
+|---|---|---|
+| `icon`| `/.config/awesome/awesome-wm-widgets/stackoverflow-widget/so-icon.svg| Path to the icon|
+| `limit` | 5 | Number of items to show in the widget
+| `tagged` | awesome-wm | Tag, or comma-separated tags |
+
+## Installation
+
+1. Clone this repo (if not cloned yet) under **~/.config/awesome/**:
+
+ ```bash
+ git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/
+ ```
+
+1. Require widget at the top of the **rc.lua**:
+
+ ```lua
+ local stackoverflow_widget = require("awesome-wm-widgets.stackoverflow-widget.stackoverflow")
+ ```
+
+1. Add widget to the tasklist:
+
+ ```lua
+ s.mytasklist, -- Middle widget
+ { -- Right widgets
+ layout = wibox.layout.fixed.horizontal,
+ ...
+ --default
+ stackoverflow_widget(),
+ --customized
+ stackoverflow_widget({
+ limit = 10
+ })
+ ...
+ ```
+
diff --git a/stackoverflow-widget/screenshot.png b/stackoverflow-widget/screenshot.png
new file mode 100644
index 0000000..b0058ab
--- /dev/null
+++ b/stackoverflow-widget/screenshot.png
Binary files differ
diff --git a/stackoverflow-widget/so-icon.svg b/stackoverflow-widget/so-icon.svg
new file mode 100644
index 0000000..5298d4c
--- /dev/null
+++ b/stackoverflow-widget/so-icon.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120"><style>.st0{fill:#bcbbbb}.st1{fill:#f48023}</style><path class="st0" d="M84.4 93.8V70.6h7.7v30.9H22.6V70.6h7.7v23.2z"/><path class="st1" d="M38.8 68.4l37.8 7.9 1.6-7.6-37.8-7.9-1.6 7.6zm5-18l35 16.3 3.2-7-35-16.4-3.2 7.1zm9.7-17.2l29.7 24.7 4.9-5.9-29.7-24.7-4.9 5.9zm19.2-18.3l-6.2 4.6 23 31 6.2-4.6-23-31zM38 86h38.6v-7.7H38V86z"/></svg> \ No newline at end of file
diff --git a/stackoverflow-widget/stackoverflow.lua b/stackoverflow-widget/stackoverflow.lua
new file mode 100644
index 0000000..3ac9bfe
--- /dev/null
+++ b/stackoverflow-widget/stackoverflow.lua
@@ -0,0 +1,123 @@
+-------------------------------------------------
+-- Stackoverflow Widget for Awesome Window Manager
+-- Shows new questions by a given tag
+-- More details could be found here:
+-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/stackoverflow-widget
+
+-- @author Pavel Makhov
+-- @copyright 2019 Pavel Makhov
+-------------------------------------------------
+
+local awful = require("awful")
+local wibox = require("wibox")
+local watch = require("awful.widget.watch")
+local json = require("json")
+local spawn = require("awful.spawn")
+local gears = require("gears")
+local beautiful = require("beautiful")
+
+local HOME_DIR = os.getenv("HOME")
+
+local GET_QUESTIONS_CMD = [[bash -c "curl --compressed -s -X GET 'http://api.stackexchange.com/2.2/questions/no-answers?page=1&pagesize=%s&order=desc&sort=activity&tagged=%s&site=stackoverflow'"]]
+
+local stackoverflow_widget = {}
+
+local function worker(args)
+
+ local args = args or {}
+
+ local icon = args.icon or HOME_DIR .. '/.config/awesome/awesome-wm-widgets/stackoverflow-widget/so-icon.svg'
+ local limit = args.limit or 5
+ local tagged = args.tagged or 'awesome-wm'
+
+ local rows = {
+ { widget = wibox.widget.textbox },
+ layout = wibox.layout.fixed.vertical,
+ }
+
+ local popup = awful.popup{
+ visible = true,
+ ontop = true,
+ visible = false,
+ shape = gears.shape.rounded_rect,
+ border_width = 1,
+ border_color = beautiful.bg_focus,
+ maximum_width = 400,
+ preferred_positions = top,
+ offset = { y = 5 },
+ widget = {}
+ }
+
+ stackoverflow_widget = wibox.widget {
+ {
+ image = icon,
+ widget = wibox.widget.imagebox
+ },
+ {
+ id = "txt",
+ widget = wibox.widget.textbox
+ },
+ layout = wibox.layout.fixed.horizontal,
+ set_text = function(self, new_value)
+ self.txt.text = new_value
+ end,
+ }
+
+ local update_widget = function(widget, stdout, stderr, _, _)
+
+ local result = json.decode(stdout)
+
+ for i = 0, #rows do rows[i]=nil end
+ for _, item in ipairs(result.items) do
+ local tags = ''
+ for i = 1, #item.tags do tags = tags .. item.tags[i] .. ' ' end
+ local row = wibox.widget {
+ {
+ {
+ {
+ text = item.title,
+ widget = wibox.widget.textbox
+ },
+ {
+ text = tags,
+ align = 'right',
+ widget = wibox.widget.textbox
+ },
+ layout = wibox.layout.align.vertical
+ },
+ margins = 8,
+ layout = wibox.container.margin
+ },
+ widget = wibox.container.background
+ }
+
+ row:connect_signal("button::release", function(_, _, _, button)
+ spawn.with_shell("google-chrome " .. item.link)
+ popup.visible = false
+ end)
+
+ row:connect_signal("mouse::enter", function(c) c:set_bg(beautiful.bg_focus) end)
+ row:connect_signal("mouse::leave", function(c) c:set_bg(beautiful.bg_normal) end)
+
+ table.insert(rows, row)
+ end
+
+ popup:setup(rows)
+ end
+
+ stackoverflow_widget:buttons(
+ awful.util.table.join(
+ awful.button({}, 1, function()
+ if popup.visible then
+ popup.visible = not popup.visible
+ else
+ popup:move_next_to(mouse.current_widget_geometry)
+ end
+ end)
+ )
+ )
+ watch(string.format(GET_QUESTIONS_CMD, limit, tagged), 300, update_widget, stackoverflow_widget)
+ return stackoverflow_widget
+end
+
+return setmetatable(stackoverflow_widget, { __call = function(_, ...) return worker(...) end })