Codebase list awesome-extra / 31e99d4
Update freedesktop Reiner Herrmann 1 year, 3 months ago
3 changed file(s) with 41 addition(s) and 46 deletion(s). Raw diff Collapse all Expand all
44 Freedesktop.org menu and desktop icons support for Awesome WM 4.x
55 -------------------------------------------------------------------
66
7 :Original author: Antonio Terceiro
7 :First author: Antonio Terceiro
88 :Maintainer: Luca CPZ
99 :Version: git
1010 :License: GNU-GPL2_
1313 Description
1414 -----------
1515
16 This is a port of awesome-freedesktop_ to Awesome_ 4.x.
16 A port of awesome-freedesktop_ to Awesome_ 4.x.
1717
1818 See branches_ for previous versions.
1919
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``.
2223
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:
2526
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.
3029 - 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).
3332
3433 Screenshot
3534 ----------
3635
3736 .. image:: screenshot.png
3837 :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
4039
4140 Installation and usage
4241 ----------------------
5454 local mime_types = {}
5555
5656 -- Icons positioning
57 local desktop_current_pos = {}
57 desktop.current_pos = {}
5858
5959 -- @return iterator on input pipe
6060 local function pipelines(...)
7373 -- @param onclick function to execute on click
7474 function desktop.add_single_icon(args, label, icon, onclick)
7575 local s = args.screen
76 local dcp = desktop.current_pos
7677
7778 -- 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
8889 end
8990
9091 local common = { screen = s, bg = "#00000000", visible = true, type = "desktop" }
9394 if icon then
9495 common.width = args.iconsize.width
9596 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
9899
99100 icon = wibox.widget {
100101 image = icon,
107108 icon_container = wibox(common)
108109 icon_container:set_widget(icon)
109110
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
111112 end
112113
113114 -- create label container
114115 if label then
115116 common.width = args.labelsize.width
116117 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
119120
120121 caption = wibox.widget {
121122 text = label,
131132 caption_container:set_widget(caption)
132133 end
133134
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
135140 end
136141
137142 -- Adds base icons (This PC, Trash, etc) to desktop
190195 -- @return files table with found entries
191196 function desktop.parse_dirs_and_files(dir)
192197 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')
194199 for path in paths do
195200 if path:match("[^/]+$") then
196201 local file = {}
0
01 --[[
12
23 Awesome-Freedesktop
1011
1112 --]]
1213
14 local Gio = require("lgi").Gio
1315 local awful_menu = require("awful.menu")
1416 local menu_gen = require("menubar.menu_gen")
1517 local menu_utils = require("menubar.utils")
16 local icon_theme = require("menubar.icon_theme")
1718
1819 local io, pairs, string, table, os = io, pairs, string, table, os
1920
2425 -- freedesktop.menu
2526 local menu = {}
2627
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
3131 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"
3433 end
3534
3635 -- Remove non existent paths in order to avoid issues
5958 -- @return awful.menu
6059 function menu.build(args)
6160 local args = args or {}
62 local icon_size = args.icon_size
6361 local before = args.before or {}
6462 local after = args.after or {}
6563 local skip_items = args.skip_items or {}
113111 for _, v in pairs(after) do _menu:add(v) end
114112 end)
115113
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
123114 -- Hold the menu in the module
124115 menu.menu = _menu
125116