;;; background.el --- -*- lexical-binding: t; -*- ;; Copyright (C) 2021 Arthur Miller ;; Author: Arthur Miller ;; Keywords: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ;;; Code: (defvar bg-walpaper-dir (expand-file-name "~/wallpapers")) (defvar bg-img-list nil) (defvar bg-frame nil) (defvar bg-buffer nil) (defvar bg-curr-image nil) (defvaralias 'bg-nd 'directory-files-no-dot-files-regexp) (defun bg-init-buffer () (unless bg-buffer (setq bg-buffer (get-buffer-create " *bg-buffer*"))) (with-current-buffer bg-buffer (with-silent-modifications (erase-buffer) (setq mode-line-format nil) (insert-image (create-image bg-curr-image))))) (defun bg-init-frame () (if (display-graphic-p) (unless bg-frame (let ((w (+ (display-pixel-width) 2)) (h (+ (display-pixel-height) 2))) (setq bg-frame (make-frame `((name . "bg-frame") (width . ,w) (height . ,h) (visibility . t) (auto-raise . nil) (skip-taskbar . t) (no-focus-on-map . t) (no-accept-focus . t) (undecorated . t) (unsplittable . t) (z-group . below) (no-other-frame . t) (minibuffer . nil) (tool-bar-lines . 0) (menu-bar-lines . 0) (left-fringe . 0) (right-fringe . 0) (border-width . 0) (internal-border-width . 0) (vertical-scroll-bars . nil) (horizontal-scroll-bars . nil)))))))) (defun bg-kill-frame () (when bg-frame (delete-frame bg-frame) (setq bg-frame nil) (kill-buffer bg-buffer) (setq bg-buffer nil))) (defun bg-get-random-image () (when bg-walpaper-dir (unless bg-img-list (setq bg-img-list (directory-files bg-walpaper-dir t bg-nd t))) (let ((index (random (length bg-img-list)))) (if (not (equal (nth index bg-img-list) bg-curr-image)) (nth index bg-img-list) (bg-get-random-image))))) (defun bg-show-background (&optional image-name) (interactive) (setq bg-curr-image (or image-name (bg-get-random-image))) (bg-init-buffer) (unless bg-frame (bg-init-frame)) (with-selected-frame bg-frame (switch-to-buffer bg-buffer)) (unless (frame-visible-p bg-frame) (make-frame-visible bg-frame))) (defun bg-hide-background () (interactive) (bg-kill-frame)) (provide 'background) ;;; background.el ends here