1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: desktop.eclass
6 # base-system@gentoo.org
7 # @BLURB: support for desktop files, menus, and icons
9 if [[ -z ${_DESKTOP_ECLASS} ]]; then
12 # @FUNCTION: make_desktop_entry
13 # @USAGE: make_desktop_entry(<command>, [name], [icon], [type], [fields])
15 # Make a .desktop file.
18 # binary: what command does the app run with ?
19 # name: the name that will show up in the menu
20 # icon: the icon to use in the menu entry
21 # this can be relative (to /usr/share/pixmaps) or
22 # a full path to an icon
23 # type: what kind of application is this?
25 # https://specifications.freedesktop.org/menu-spec/latest/apa.html
26 # if unset, function tries to guess from package's category
27 # fields: extra fields to append to the desktop file; a printf string
29 make_desktop_entry() {
30 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable"
33 local name=${2:-${PN}}
34 local icon=${3:-${PN}}
38 if [[ -z ${type} ]] ; then
39 local catmaj=${CATEGORY%%-*}
40 local catmin=${CATEGORY##*-}
44 accessibility) type="Utility;Accessibility";;
46 antivirus) type=System;;
47 arch) type="Utility;Archiving";;
48 backup) type="Utility;Archiving";;
49 cdr) type="AudioVideo;DiscBurning";;
50 dicts) type="Office;Dictionary";;
51 doc) type=Documentation;;
52 editors) type="Utility;TextEditor";;
53 emacs) type="Development;TextEditor";;
54 emulation) type="System;Emulator";;
55 laptop) type="Settings;HardwareSettings";;
57 pda) type="Office;PDA";;
58 vim) type="Development;TextEditor";;
59 xemacs) type="Development;TextEditor";;
69 action|fps) type=ActionGame;;
70 arcade) type=ArcadeGame;;
71 board) type=BoardGame;;
72 emulation) type=Emulator;;
74 puzzle) type=LogicGame;;
75 roguelike) type=RolePlaying;;
76 rpg) type=RolePlaying;;
77 simulation) type=Simulation;;
78 sports) type=SportsGame;;
79 strategy) type=StrategyGame;;
108 type="AudioVideo;${type}"
115 dialup) type=Dialup;;
116 ftp) type=FileTransfer;;
117 im) type=InstantMessaging;;
118 irc) type=IRCClient;;
122 p2p) type=FileTransfer;;
123 voip) type=Telephony;;
125 type="Network;${type}"
130 astro*) type=Astronomy;;
132 calc*) type=Calculator;;
133 chem*) type=Chemistry;;
134 elec*) type=Electronics;;
137 physics) type=Physics;;
138 visual*) type=DataVisualization;;
140 type="Education;Science;${type}"
149 client) type=WebBrowser;;
151 type="Network;${type}"
159 local slot=${SLOT%/*}
160 if [[ ${slot} == "0" ]] ; then
161 local desktop_name="${PN}"
163 local desktop_name="${PN}-${slot}"
165 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop"
166 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop
168 # Don't append another ";" when a valid category value is provided.
169 type=${type%;}${type:+;}
171 if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
172 ewarn "As described in the Icon Theme Specification, icon file extensions are not"
173 ewarn "allowed in .desktop files if the value is not an absolute path."
177 cat <<-EOF > "${desktop}"
181 Comment=${DESCRIPTION}
188 if [[ ${fields:-=} != *=* ]] ; then
189 # 5th arg used to be value to Path=
190 ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}"
191 fields="Path=${fields}"
193 [[ -n ${fields} ]] && printf '%b\n' "${fields}" >> "${desktop}"
196 # wrap the env here so that the 'insinto' call
197 # doesn't corrupt the env of the caller
198 insinto /usr/share/applications
200 ) || die "installing desktop file failed"
203 # @FUNCTION: make_session_desktop
204 # @USAGE: <title> <command> [command args...]
206 # Make a GDM/KDM Session file. The title is the file to execute to start the
207 # Window Manager. The command is the name of the Window Manager.
209 # You can set the name of the file via the ${wm} variable.
210 make_session_desktop() {
211 [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1
212 [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1
216 local desktop=${T}/${wm:-${PN}}.desktop
219 cat <<-EOF > "${desktop}"
222 Comment=This session logs you into ${title}
229 # wrap the env here so that the 'insinto' call
230 # doesn't corrupt the env of the caller
231 insinto /usr/share/xsessions
239 # Install the list of .desktop menu files into the appropriate directory
240 # (/usr/share/applications).
243 # wrap the env here so that the 'insinto' call
244 # doesn't corrupt the env of the caller
246 insinto /usr/share/applications
248 if [[ -f ${i} ]] ; then
251 elif [[ -d ${i} ]] ; then
252 for j in "${i}"/*.desktop ; do
265 # @USAGE: <menu> <newname>
267 # Like all other new* functions, install the specified menu as newname.
270 # wrap the env here so that the 'insinto' call
271 # doesn't corrupt the env of the caller
272 insinto /usr/share/applications
277 # @FUNCTION: _iconins
280 # function for use in doicon and newicon
283 # wrap the env here so that the 'insinto' call
284 # doesn't corrupt the env of the caller
285 local funcname=$1; shift
290 while [[ $# -gt 0 ]] ; do
293 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
299 16|22|24|32|36|48|64|72|96|128|192|256|512)
300 size=${size}x${size};;
304 eerror "${size} is an unsupported icon size!"
315 if [[ -z ${size} ]] ; then
316 insinto /usr/share/pixmaps
318 insinto /usr/share/icons/${theme}/${size}/${context}
321 if [[ ${funcname} == doicon ]] ; then
322 if [[ -f $1 ]] ; then
324 elif [[ -d $1 ]] ; then
326 doins "${1}"/*.{png,svg}
329 eerror "${1} is not a valid file/directory!"
338 if [[ ${funcname} == newicon ]] ; then
345 # @USAGE: [options] <icons>
347 # Install icon into the icon directory /usr/share/icons or into
348 # /usr/share/pixmaps if "--size" is not set.
349 # This is useful in conjunction with creating desktop/menu files.
354 # !!! must specify to install into /usr/share/icons/... !!!
355 # size of the icon, like 48 or 48x48
356 # supported icon sizes are:
357 # 16 22 24 32 36 48 64 72 96 128 192 256 512 scalable
361 # defaults to "hicolor"
363 # icons: list of icons
365 # example 1: doicon foobar.png fuqbar.svg suckbar.png
366 # results in: insinto /usr/share/pixmaps
367 # doins foobar.png fuqbar.svg suckbar.png
369 # example 2: doicon -s 48 foobar.png fuqbar.png blobbar.png
370 # results in: insinto /usr/share/icons/hicolor/48x48/apps
371 # doins foobar.png fuqbar.png blobbar.png
374 _iconins ${FUNCNAME} "$@"
378 # @USAGE: [options] <icon> <newname>
380 # Like doicon, install the specified icon as newname.
383 # example 1: newicon foobar.png NEWNAME.png
384 # results in: insinto /usr/share/pixmaps
385 # newins foobar.png NEWNAME.png
387 # example 2: newicon -s 48 foobar.png NEWNAME.png
388 # results in: insinto /usr/share/icons/hicolor/48x48/apps
389 # newins foobar.png NEWNAME.png
392 _iconins ${FUNCNAME} "$@"