I've two modules mocscroll.lua and calendar.lua (attached, with rc.lua).

If I set the timeout for the calendar notification to zero, and then enter the datewidget (which creates the calendar notification) then it breaks my mocp widget (text stops scrolling). Having the timeout at one creates no trouble.

If with the mouse I re-enter the moc widget, its box is displayed normally, but 
does not time-out as it should.

also it seems _all_ timeouts are broken for naughty.notifications thereafter (eg they all stay until I right click them) except for the calendar.

If I re-enter the moc widget, its box is displayed normally, but does not 
time-out as it should.

I put some print() statements into the mocp widget and the widg() function is never even entered after the calendar notification pops up. That to me is just weird, because the mocscroll.widg() function is registered in a hook.timer...

idk how these are related unless naughty is somehow clearing this hook.timer 
when the notification is created.

So I also tried:

echo 'naughty.notify({title="foo", text="bar", timeout=0}))' | awesome-client

the same behavior follows, except that the calendar notification is not 
affected.

Anyone can help debug this? I'd appreciate it.

-bioe007
local string = string
local os = os
local math = math
local awful = require("awful")
local beautiful = require("beautiful")
local naughty = require("naughty")
local markup = require("markup")
module("calendar")

local calendar = nil
local offset = 0

function remove_calendar()
  if calendar ~= nil then
    naughty.destroy(calendar)
    calendar = nil
    offset = 0
  end
end

function add_calendar(inc_offset)
  local save_offset = offset
  remove_calendar()
  offset = save_offset + (inc_offset or 0)
  local datespec = os.date("*t")
  datespec = datespec.year * 12 + datespec.month - 1 + offset
  datespec = (datespec % 12 + 1) .. " " .. math.floor(datespec / 12)
  local cal = awful.util.pread("cal -m " .. datespec)
  cal = string.gsub(cal, "^%s*(.-)%s*$", "%1")
  calendar = naughty.notify({
    text = markup.font("monospace", os.date("%a, %d %B %Y") .. "\n" .. cal),
    timeout = 1, hover_timeout = 0.5,
    width = beautiful.calendar_w or 160,
    bg = beautiful.calendar_bg or beautiful.bg_focus or #000000,
    fg = beautiful.calendar_fg or beautiful.fg_focus or #ffffff})
end

-- vim:set filetype=lua fdm=marker tabstop=4 shiftwidth=4 expandtab smarttab 
autoindent smartindent: --
local button = button
local io = io
local string = string
local awful = require("awful")
local beautiful = require("beautiful")
local naughty = require("naughty")
local markup = require("markup")
local print = print -- debug

module("mocscroll")

local mocbox = nil
settings = {}
settings.iScroller = 1
settings.MAXCH = 15
settings.mocInterval = 0.75

---{{{ local function mocstate()
local function mocstate()

    local np = {}
    np.file = {}
    np.file = io.popen('pgrep mocp')

    if np.file == nil then
        np.file:close()
        settings.widget.text = "moc stopped"
        settings.musicstate = "-"
        settings.mocInterval = 2
        return false
    else
        np.file:close()

        -- pgrep returned something so we can now check for play|pause
        np.file = io.popen('mocp -Q %state')
        np.strng = np.file:read()
        np.file:close()

        settings.musicstate = np.strng
        return np.strng
    end
end
---}}}

---{{{ local function moctitle(delim)
local function moctitle(delim)

    local eol = delim or " "
    local np = {}

    -- grab artist
    np.file = io.popen('mocp -Q %artist')
    np.artist = np.file:read() .. ":" .. eol
    np.file:close()

    -- grab song
    np.file = io.popen('mocp -Q %song')
    np.song =string.gsub( string.gsub(np.file:read(),"^%d*",""),"%(.*","") .. 
eol
    np.file:close()

    -- return for widget text
    if not delim then return np.artist..np.song end

    -- get time, etc for notify
    np.file = io.popen('mocp -Q %album')
    np.strng = "Artist: "..string.gsub(np.artist,":","").."Song:   
"..np.song.."Album:  "..np.file:read()..eol
    np.file:close()

    np.file = io.popen('mocp -Q %ct')
    np.strng = np.strng.."Time:   "..np.file:read() .." [ " 
    np.file:close()

    np.file = io.popen('mocp -Q %tt')
    np.strng = np.strng..np.file:read() .." ]" 
    np.file:close()

    return np.strng
end
---}}}

---{{{ local function notdestroy()
local function notdestroy()
    if mocbox ~= nil then
        naughty.destroy(mocbox)
        mocbox = nil
    end
end
---}}}

---{{{ function mocnotify(args)
function mocnotify(args)
    print("in notify")

    notdestroy()

    print("past destroy")

    local np = {}
    np.state = nil
    np.strng = ""
    np.state = mocstate()
    if np.state == false then
        return
    else
        np.strng = moctitle("\n")
    end
    np.strng = markup.fg( beautiful.fg_focus, markup.font("monospace", 
np.strng.."  "))  
    mocbox = naughty.notify({ 
        title = markup.font("monospace","Now Playing:"),
        text = np.strng, hover_timeout = 0.5,
        -- icon = 
"/usr/share/icons/gnome/24x24/actions/edia-playback-start.png", icon_size = 24,
        run = function() mocplay(); mocnotify() end
    })
end
---}}}

---{{{ function mocplay() 
-- easier way to check|run mocp
function mocplay() 
  if settings.musicstate == "STOP" then
    awful.util.spawn('mocp --play') 
  elseif settings.musicstate == "PLAY" then
    awful.util.spawn('mocp --next')
  else 
    awful.util.spawn('mocp --toggle-pause')
  end
end
---}}}

function setwidget(w)
    settings.widget = w
end

-- {{{ mocp widget, scrolls text
function widg(tb)
    local np = {}

    np.strng = mocstate()
    if not np.strng then
        settings.widget.text = "moc stopped"
        settings.musicstate = "-"
        return
    else

        -- this just helps my keybindings work better 
        settings.musicstate = np.strng

        -- this sets the symbolic prefix based on where moc is playing | 
(stopped or paused)
        if np.strng == "PAUSE" or np.strng == "STOP" then
            prefix = "|| "
            mocInterval = 2
        else
            prefix = ">> "
            mocInterval = 0.75
        end

        -- extract a substring, putting it after the 
        np.strng = moctitle()
        np.rtn = 
string.sub(np.strng,settings.iScroller,settings.MAXCH+settings.iScroller-1) 

        -- if our index and settings.MAXCH count are bigger than the string, 
wrap around to the beginning and
        -- add enough to make it look circular
        if settings.MAXCH+settings.iScroller > (np.strng):len() then
            np.rtn = np.rtn .. 
string.sub(np.strng,1,(settings.MAXCH+settings.iScroller-1)-np.strng:len())
        end

        np.rtn = awful.util.escape(np.rtn)
        settings.widget.text = markup.fg(beautiful.fg_normal,prefix) .. 
markup.fg(beautiful.fg_sb_hi,np.rtn) 

        if settings.iScroller <= np.strng:len() then
            settings.iScroller = settings.iScroller +1
        else
            settings.iScroller = 1
        end
    end
    print(settings.iScroller)
end
-- }}}

-- vim: filetype=lua fdm=marker tabstop=4 shiftwidth=4 expandtab smarttab 
autoindent smartindent:

require("mocp")
require("calendar")

--snip--
--
-- {{{ -- DATE widget
datewidget = widget({
    type = 'textbox',
    name = 'datewidget',
    align = 'right',
})

datewidget.mouse_enter = function() calendar.add_calendar() end
datewidget.mouse_leave = function() calendar.remove_calendar end

datewidget:buttons({ 
  button({ }, 4, function() calendar.add_calendar(-1) end),
  button({ }, 5, function() calendar.add_calendar(1) end), 
})
wicked.register(datewidget, wicked.widgets.date,
   markup.fg(beautiful.fg_sb_hi, '%k:%M %D'))

-- }}}

-- {{{ -- MOCP Widget
mocpwidget = widget({ type = 'textbox', name = 'mocpwidget', align = 'right'})
mocscroll.setwidget(mocpwidget)
mocpwidget.width = 112
mocpwidget:buttons({
    button({ }, 1, function () mocplay(); mocscroll.mocnotify() end ),
    button({ }, 2, function () awful.util.spawn('mocp --toggle-pause') end),
    button({ }, 3, function () awful.util.spawn('mocp --previous'); mocnotify() 
end)
})
mocpwidget.mouse_enter = function() mocscroll.mocnotify({"entered"}) end
awful.hooks.timer.register (1,mocscroll.widg)
---}}}

--snip--

Reply via email to