Update freedesktop
Reiner Herrmann
1 year, 3 months ago
4 | 4 | Freedesktop.org menu and desktop icons support for Awesome WM 4.x |
5 | 5 | ------------------------------------------------------------------- |
6 | 6 | |
7 | :Original author: Antonio Terceiro | |
7 | :First author: Antonio Terceiro | |
8 | 8 | :Maintainer: Luca CPZ |
9 | 9 | :Version: git |
10 | 10 | :License: GNU-GPL2_ |
13 | 13 | Description |
14 | 14 | ----------- |
15 | 15 | |
16 | This is a port of awesome-freedesktop_ to Awesome_ 4.x. | |
16 | A port of awesome-freedesktop_ to Awesome_ 4.x. | |
17 | 17 | |
18 | 18 | See branches_ for previous versions. |
19 | 19 | |
20 | Since the introduction of Menubar_ as core library for providing Freedesktop.org menu functionalities in Awesome, | |
21 | we can now avoid all the dirty work by just exploiting ``menubar.utils`` functions. | |
20 | Since the introduction of Menubar_ as a core library to provide Freedesktop.org | |
21 | functionalities in Awesome, we can now avoid the dirty work by simply exploiting | |
22 | ``menubar.utils``. | |
22 | 23 | |
23 | At the initial status of this port, the menu is pretty much complete, while the desktop icons are very basic, | |
24 | so the long term objective will be to complete functionalities on this part too. | |
24 | At the moment, the menu is complete, while the desktop icons are rather simple. Our goal | |
25 | is to add the following features: | |
25 | 26 | |
26 | More specifically, the todo list is: | |
27 | ||
28 | - A better way to handle desktop icons path | |
29 | - Ability to drag and line up icons | |
27 | - A better way to handle desktop icons path. | |
28 | - Ability to drag and line up icons. | |
30 | 29 | - Event-based signals, in particular: |
31 | - Updating trash icon according to its status | |
32 | - Dynamic update (no need to restart Awesome to see changes on desktop) | |
30 | - Updating trash icon according to its status. | |
31 | - Dynamic update (no need to restart Awesome to see changes on the desktop). | |
33 | 32 | |
34 | 33 | Screenshot |
35 | 34 | ---------- |
36 | 35 | |
37 | 36 | .. image:: screenshot.png |
38 | 37 | :align: center |
39 | :alt: Showcase of Freedesktop support in Awesome, using Adwaita icons | |
38 | :alt: Showcase of Freedesktop.org support in Awesome, using Adwaita icons | |
40 | 39 | |
41 | 40 | Installation and usage |
42 | 41 | ---------------------- |
54 | 54 | local mime_types = {} |
55 | 55 | |
56 | 56 | -- Icons positioning |
57 | local desktop_current_pos = {} | |
57 | desktop.current_pos = {} | |
58 | 58 | |
59 | 59 | -- @return iterator on input pipe |
60 | 60 | local function pipelines(...) |
73 | 73 | -- @param onclick function to execute on click |
74 | 74 | function desktop.add_single_icon(args, label, icon, onclick) |
75 | 75 | local s = args.screen |
76 | local dcp = desktop.current_pos | |
76 | 77 | |
77 | 78 | -- define icon dimensions and position |
78 | if not desktop_current_pos[s] then | |
79 | desktop_current_pos[s] = { x = (screen[s].geometry.x + args.iconsize.width + args.margin.x), y = 40 } | |
80 | end | |
81 | ||
82 | local totheight = (icon and args.iconsize.height or 0) + (label and args.labelsize.height or 0) | |
83 | if totheight == 0 then return end | |
84 | ||
85 | if desktop_current_pos[s].y + totheight > screen[s].geometry.height - 40 then | |
86 | desktop_current_pos[s].x = desktop_current_pos[s].x + args.labelsize.width + args.iconsize.width + args.margin.x | |
87 | desktop_current_pos[s].y = 40 | |
79 | if not dcp[s] then | |
80 | dcp[s] = { x = (screen[s].geometry.x + args.iconsize.width + args.margin.x), y = screen[s].geometry.y + 20 + args.margin.y } | |
81 | end | |
82 | ||
83 | local tot_height = (icon and args.iconsize.height or 0) + (label and args.labelsize.height or 0) | |
84 | if tot_height == 0 then return end | |
85 | ||
86 | if dcp[s].y + tot_height > screen[s].geometry.y + screen[s].geometry.height - 20 - args.margin.y then | |
87 | dcp[s].x = dcp[s].x + args.labelsize.width + args.iconsize.width + args.margin.x | |
88 | dcp[s].y = 20 + args.margin.y | |
88 | 89 | end |
89 | 90 | |
90 | 91 | local common = { screen = s, bg = "#00000000", visible = true, type = "desktop" } |
93 | 94 | if icon then |
94 | 95 | common.width = args.iconsize.width |
95 | 96 | common.height = args.iconsize.height |
96 | common.x = desktop_current_pos[s].x | |
97 | common.y = desktop_current_pos[s].y | |
97 | common.x = dcp[s].x | |
98 | common.y = dcp[s].y | |
98 | 99 | |
99 | 100 | icon = wibox.widget { |
100 | 101 | image = icon, |
107 | 108 | icon_container = wibox(common) |
108 | 109 | icon_container:set_widget(icon) |
109 | 110 | |
110 | desktop_current_pos[s].y = desktop_current_pos[s].y + args.iconsize.height + 5 | |
111 | dcp[s].y = dcp[s].y + args.iconsize.height + 5 | |
111 | 112 | end |
112 | 113 | |
113 | 114 | -- create label container |
114 | 115 | if label then |
115 | 116 | common.width = args.labelsize.width |
116 | 117 | common.height = args.labelsize.height |
117 | common.x = desktop_current_pos[s].x - (args.labelsize.width/2) + args.iconsize.width/2 | |
118 | common.y = desktop_current_pos[s].y | |
118 | common.x = dcp[s].x - (args.labelsize.width/2) + args.iconsize.width/2 | |
119 | common.y = dcp[s].y | |
119 | 120 | |
120 | 121 | caption = wibox.widget { |
121 | 122 | text = label, |
131 | 132 | caption_container:set_widget(caption) |
132 | 133 | end |
133 | 134 | |
134 | desktop_current_pos[s].y = desktop_current_pos[s].y + args.labelsize.height + args.margin.y | |
135 | dcp[s].y = dcp[s].y + args.labelsize.height + args.margin.y | |
136 | ||
137 | desktop.current_pos = dcp | |
138 | ||
139 | return dcp | |
135 | 140 | end |
136 | 141 | |
137 | 142 | -- Adds base icons (This PC, Trash, etc) to desktop |
190 | 195 | -- @return files table with found entries |
191 | 196 | function desktop.parse_dirs_and_files(dir) |
192 | 197 | local files = {} |
193 | local paths = pipelines('find '..dir..' -maxdepth 1 -type d | tail -1') | |
198 | local paths = pipelines('find '..dir..' -maxdepth 1 -type d |sort|tail -n +1') | |
194 | 199 | for path in paths do |
195 | 200 | if path:match("[^/]+$") then |
196 | 201 | local file = {} |
0 | ||
0 | 1 | --[[ |
1 | 2 | |
2 | 3 | Awesome-Freedesktop |
10 | 11 | |
11 | 12 | --]] |
12 | 13 | |
14 | local Gio = require("lgi").Gio | |
13 | 15 | local awful_menu = require("awful.menu") |
14 | 16 | local menu_gen = require("menubar.menu_gen") |
15 | 17 | local menu_utils = require("menubar.utils") |
16 | local icon_theme = require("menubar.icon_theme") | |
17 | 18 | |
18 | 19 | local io, pairs, string, table, os = io, pairs, string, table, os |
19 | 20 | |
24 | 25 | -- freedesktop.menu |
25 | 26 | local menu = {} |
26 | 27 | |
27 | -- Determines if a path points to a directory, by checking if it can be read | |
28 | -- (which is `nil` also for empty files) and if its size is not 0. | |
29 | -- @author blueyed | |
30 | -- @param path the path to check | |
28 | -- Check if a path is a directory. | |
29 | -- @tparam string path The directory path | |
30 | -- @treturn boolean True if path exists and is a directory | |
31 | 31 | function menu.is_dir(path) |
32 | local f = io.open(path) | |
33 | return f and not f:read(0) and f:seek("end") ~= 0 and f:close() | |
32 | return Gio.File.new_for_path(path):query_file_type({}) == "DIRECTORY" | |
34 | 33 | end |
35 | 34 | |
36 | 35 | -- Remove non existent paths in order to avoid issues |
59 | 58 | -- @return awful.menu |
60 | 59 | function menu.build(args) |
61 | 60 | local args = args or {} |
62 | local icon_size = args.icon_size | |
63 | 61 | local before = args.before or {} |
64 | 62 | local after = args.after or {} |
65 | 63 | local skip_items = args.skip_items or {} |
113 | 111 | for _, v in pairs(after) do _menu:add(v) end |
114 | 112 | end) |
115 | 113 | |
116 | -- Set icon size | |
117 | if icon_size then | |
118 | for _,v in pairs(menu_gen.all_categories) do | |
119 | v.icon = icon_theme():find_icon_path(v.icon_name, icon_size) | |
120 | end | |
121 | end | |
122 | ||
123 | 114 | -- Hold the menu in the module |
124 | 115 | menu.menu = _menu |
125 | 116 |