Previous: , Up: Applications Menu   [Contents][Index]


15.2.3 Desktop File Processing

In this section it is shown how Sawfish processes desktop file entries while building the applications menu. Each entry passes through many filters, and they’re what you may want to customize.

Desktop file entries are expressed as a list. Here is an example of emacs.desktop file before any filters are performed:

("Desktop Entry"
	   ("Name" . "Emacs Text Editor")
	   ("Name[de]" . "Emacs Texteditor")
	   ("GenericName" . "Text Editor")
	   ("Comment" . "Edit text")
	   ("Exec" . "emacs %f")
	   ("Icon" . "emacs-icon")
	   ("Type" . "Application")
	   ("Terminal" . "false")
	   ("Categories" . "Development;TextEditor;")
	   ("StartupWMClass" . "Emacs"))

It then gets split into two lists. The original “Categories” key contains several values, and each of new entries has “Category” key which contains only one of the original categories.

("Desktop Entry"
	   ("Name" . "Emacs Text Editor")
	   ("Name[de]" . "Emacs Texteditor")
	   ("GenericName" . "Text Editor")
	   ("Comment" . "Edit text")
	   ("Exec" . "emacs %f")
	   ("Icon" . "emacs-icon")
	   ("Type" . "Application")
	   ("Terminal" . "false")
	   ("Categories" . "Development;TextEditor;")
	   ("Cateogry" . "Development") ; Look here
	   ("StartupWMClass" . "Emacs"))

("Desktop Entry"
	   ("Name" . "Emacs Text Editor")
	   ("Name[de]" . "Emacs Texteditor")
	   ("GenericName" . "Text Editor")
	   ("Comment" . "Edit text")
	   ("Exec" . "emacs %f")
	   ("Icon" . "emacs-icon")
	   ("Type" . "Application")
	   ("Terminal" . "false")
	   ("Categories" . "Development;TextEditor;")
	   ("Cateogry" . "TextEditor") ; Look here
	   ("StartupWMClass" . "Emacs"))

This is the entry list format that is used in all of the later filters. All filtering functions should accept such an entry list as its argument, and all filtering functions should either return nil or an entry list. If fdo-associate-categories is t then the “Category” key will be changed to the main category that will eventually show up in the apps-menu. The keys that are used by the applications menu are currently,

Filters

Filters are functions, either pre-defined or user-defined, which take one argument, a desktop file entry. You can set your filter to the apps-menu-filter variable.

Here we show an example user-defined filter, and all pre-defined filters, which are also available to user codes.

;; This will move emacs to the ``util'' category, in addition to the
;; operations done by default filter.
(setq apps-menu-filter
      (lambda (ent)
	(let ((ent (fdo-default-filter ent)))
	  (when ent
	    (cond ((string-match "[Ee]macs" (cdr (assoc "Name" ent)) nil t)
		   (rplacd (assoc "Category" ent) "util")))
	    ent))))

The pre-defined filters:

(define (fdo-nodisplay-filter fdol)
  "Return the desktop-file-list if NoDisplay is False, or if NoDisplay is
not present in the desktop-file-list"
  (if (assoc "NoDisplay" fdol)
      ;; [Ff] means match to "false"
      (if (string-match "[Ff]" (cdr (assoc "NoDisplay" fdol)))
      	  fdol)
    fdol))

(define (fdo-hidden-filter fdol)
  "Return the desktop-file-list if Hidden is False, or if Hidden is
not present in the desktop-file-list"
  (if (assoc "Hidden" fdol)
      (if (string-match "[Ff]" (string-downcase (cdr (assoc "OnlyShowIn" fdol))))
	  fdol)
    fdol))

(define (fdo-onlyshowin-filter fdol)
  "Return the desktop-file-list if OnlyShowIn matches `desktop-environment',
or if OnlyShowIn is not present in the desktop-file-list"
  (if (assoc "OnlyShowIn" fdol)
      (if (string-match desktop-environment (string-downcase (cdr (assoc "OnlyShowIn" fdol))))
	  fdol)
    fdol))

(define (fdo-notshowin-filter fdol)
  "Return the desktop-file-list if NotShowIn does not match `desktop-environment',
or if NotShowIn is not present in the desktop-file-list"
  (if (assoc "NotShowIn" fdol)
      (if (not (string-match desktop-environment (string-downcase (cdr (assoc "NotShowIn" fdol)))))
	  fdol)
    fdol))

(define (fdo-associate-categories-filter fdol)
  "If `apps-menu-associate-categories' is true, filter the
desktop-entry through `fdo-associate-categories'."
  (when fdol
    (if apps-menu-associate-categories
	(associate-categories fdol)
      fdol)))

(define (fdo-toplevel-filter fdol)
  "Return the desktop-file-list if the `Category' is of the
Top-Level variety."
  (when fdol
    (if (not (equal "Top-Level" (cdr (assoc "Category" fdol))))
	fdol)))

(define (fdo-default-filter fdol)
  "The default fdo-filter, combines the above."
  (fdo-toplevel-filter
   (fdo-hidden-filter
    (fdo-notshowin-filter
     (fdo-onlyshowin-filter
      (fdo-nodisplay-filter fdol))))))

(setq apps-menu-filter fdo-default-filter)

Previous: , Up: Applications Menu   [Contents][Index]