From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.devel Subject: Re: RFC: status icon support Date: Sun, 13 Jan 2008 18:01:40 -0700 Message-ID: References: <200801120157.m0C1v6WL020654@oogie-boogie.ics.uci.edu> <87lk6t2p7b.fsf@grepfind.mwolson.org> Reply-To: Tom Tromey NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1200274520 16561 80.91.229.12 (14 Jan 2008 01:35:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 14 Jan 2008 01:35:20 +0000 (UTC) Cc: emacs-devel@gnu.org To: Michael Olson Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 14 02:35:42 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JEEEm-0008Tm-7g for ged-emacs-devel@m.gmane.org; Mon, 14 Jan 2008 02:35:40 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JEEEN-000446-W5 for ged-emacs-devel@m.gmane.org; Sun, 13 Jan 2008 20:35:16 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JEEEK-00043c-52 for emacs-devel@gnu.org; Sun, 13 Jan 2008 20:35:12 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JEEEI-00043A-Ju for emacs-devel@gnu.org; Sun, 13 Jan 2008 20:35:11 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JEEEI-000437-Ep for emacs-devel@gnu.org; Sun, 13 Jan 2008 20:35:10 -0500 Original-Received: from mx1.redhat.com ([66.187.233.31]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JEEEE-0008VF-R7; Sun, 13 Jan 2008 20:35:07 -0500 Original-Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m0E1Z5eg008624; Sun, 13 Jan 2008 20:35:05 -0500 Original-Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m0E1Z5rU002108; Sun, 13 Jan 2008 20:35:05 -0500 Original-Received: from opsy.redhat.com (ton.yyz.redhat.com [10.15.16.15]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m0E1Z4EE020796; Sun, 13 Jan 2008 20:35:04 -0500 Original-Received: by opsy.redhat.com (Postfix, from userid 500) id 37F9E37824D; Sun, 13 Jan 2008 18:01:40 -0700 (MST) X-Attribution: Tom In-Reply-To: <87lk6t2p7b.fsf@grepfind.mwolson.org> (Michael Olson's message of "Sun\, 13 Jan 2008 20\:03\:36 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.990 (gnu/linux) X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:86861 Archived-At: >>>>> "Michael" == Michael Olson writes: Michael> [ ... excellent bug report ] Michael> I suspect a race condition. Yes, I think you are right. I am not sure but maybe the answer is to call gtk_main_iteration to flush the gtk event queue. I am testing that. If that doesn't work, I guess I'll have to learn more about the Emacs event stuff... scary. I may need help. Michael> Once this issue is fixed, I'd love to see this feature hit Michael> Emacs CVS. It will be particularly nice for ERC once your Michael> erc-status.el is adapted to work with the new code. I've appended my updated erc-status.el. I haven't tried it at all, I just rewrote it to the new API. Michael> ;; => "Couldn't connect to notification server" Michael> ;; => libnotify-Message: Unable to get session bus: Failed to Michael> ;; execute dbus-launch to autolaunch D-Bus session Michael> ;; => Does not show "foo" popup Are you running dbus? And do you have a system tray in your panel? I'm not an expert here, either, but I would only expect these errors if one of those answers is "no". FWIW I do see the racy behavior you pointed out, but I don't see this error. I'm running a rather standard Gnome desktop -- whatever is in Fedora Core 6. My panel does have a system tray. The notification stuff is cross-desktop, so it should also work if you are a KDE user. I have not tested that with the Emacs-based code, but I have tried out other system-tray-using Gnome applications on KDE. Thanks for taking the time to try this out. Tom ;;; erc-status.el --- notification area support for ERC ;; Copyright (C) 2007, 2008 Tom Tromey ;; Author: Tom Tromey ;; Version: 0.2 ;; Keywords: comm ;; This file is not (yet) part of GNU Emacs. ;; However, it is distributed under the same license. ;; GNU Emacs 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, or (at your option) ;; any later version. ;; GNU Emacs 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 GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; This provides nice support for the notification area to ERC. In ;; particular it: ;; * Will blink the icon when you get a private message or are paged ;; in a channel. ;; * Left-click on the blinking icon will show the appropriate channel ;; buffer in some frame (which is then raised). If there are ;; multiple pages at once, it will show one and you can click again ;; to go to the next one. ;; * Will pop up notification bubbles when you connect to or ;; disconnect from a server. ;; This is regular erc module named 'status'; you can enable it as you ;; would any other module. ;; TO DO: ;; - make tool tip show some kind of real status ...? ;; - use a nicer icon ;; - add a menu ;; - integrate with auto-query a bit better ;; - let left click use specified frame or make a new frame? ;; - when last server connection is closed, remove icon (require 'systray) (require 'erc) ;; The status icon object. (defvar erc-status-status-icon nil) ;; List of ERC buffers that caused the status icon to blink. (defvar erc-status-buffer-list nil) (defun erc-status-remove-buffer (buffer) ;; If the list is not empty, and removing an element makes the list ;; empty, stop blinking. (and erc-status-buffer-list (not (setq erc-status-buffer-list (delq buffer erc-status-buffer-list))) (modify-status-icon erc-status-status-icon '((blinking . nil))))) (defun erc-status-add-buffer (buffer) (and (not (erc-buffer-visible buffer)) (progn (modify-status-icon erc-status-status-icon '((blinking . t))) (or (memq buffer erc-status-buffer-list) (setq erc-status-buffer-list (cons buffer erc-status-buffer-list)))))) (defun erc-status-match-hook (match-type nick message) ;; Look for user's nick and make the icon blink. (if (eq match-type 'current-nick) (erc-status-add-buffer (current-buffer)))) (defun erc-status-buffer-killed () ;; If one of our buffers was killed, remove it. (erc-status-remove-buffer (current-buffer))) (defun erc-status-window-configuration-changed () (let ((new-list) (iter erc-status-buffer-list)) (while iter (or (erc-buffer-visible (car iter)) (setq new-list (cons (car iter) new-list))) (setq iter (cdr iter))) (or (setq erc-status-buffer-list new-list) (modify-status-icon erc-status-status-icon '((blinking . nil)))))) (defun erc-status-disconnected (nick ip reason) ;; FIXME: should mention the server from which we were disconnected. ;; FIXME: add a :action to reconnect. (show-status-icon-message erc-status-status-icon (concat "Disconnected: " reason))) (defun erc-status-after-connect (server nick) (show-status-icon-message erc-status-status-icon (concat "Connected to " server " as " nick))) (defun erc-status-select-first-buffer () "Switch to the first ERC buffer requiring your attention. If there is no such buffer, do nothing." (when erc-status-buffer-list (switch-to-buffer (car erc-status-buffer-list)) (raise-frame))) ;; From: http://www.emacswiki.org/cgi-bin/wiki/ErcPageMe ;; Then modified to suit. (defun erc-status-PRIVMSG (proc parsed) (let* ((nick (car (erc-parse-user (erc-response.sender parsed)))) (target (car (erc-response.command-args parsed))) (msg (erc-response.contents parsed)) (query (if (not erc-query-on-unjoined-chan-privmsg) nick (if (erc-current-nick-p target) nick target)))) (when (and (erc-current-nick-p target) (not (erc-is-message-ctcp-and-not-action-p msg))) ;; Note: assumes you are using auto-query. (erc-status-add-buffer (erc-get-buffer query proc)))) ;; Always return nil. nil) (define-erc-module status nil "Notification area support for ERC." ;; Enable. ((unless erc-status-status-icon (setq erc-status-status-icon (make-status-icon '((help-echo . "ERC - IRC client for Emacs") (click-callback . #'erc-status-select-first-buffer))))) (add-hook 'erc-text-matched-hook 'erc-status-match-hook) (add-hook 'kill-buffer-hook 'erc-status-buffer-killed) (add-hook 'window-configuration-change-hook 'erc-status-window-configuration-changed) (add-hook 'erc-after-connect 'erc-status-after-connect) (add-hook 'erc-disconnected-hook 'erc-status-disconnected) ;; FIXME: Must come *after* erc-auto-query. Some sort of ;; auto-query hook or the like would be good here. (add-hook 'erc-server-PRIVMSG-functions 'erc-status-PRIVMSG t)) ;; Disable. ((when erc-status-status-icon (delete-status-icon erc-status-status-icon) (setq erc-status-status-icon nil)) (remove-hook 'erc-text-matched-hook 'erc-status-match-hook) (remove-hook 'kill-buffer-hook 'erc-status-buffer-killed) (remove-hook 'window-configuration-change-hook 'erc-status-window-configuration-changed) (remove-hook 'erc-after-connect 'erc-status-after-connect) (remove-hook 'erc-disconnected-hook 'erc-status-disconnected) (remove-hook 'erc-server-PRIVMSG-functions 'erc-status-PRIVMSG))) ;;; erc-status.el ends here