diff --git a/tests/examples/wibox/widget/calendar/fn_embed_cell.lua b/tests/examples/wibox/widget/calendar/fn_embed_cell.lua new file mode 100644 index 00000000..91155e8c --- /dev/null +++ b/tests/examples/wibox/widget/calendar/fn_embed_cell.lua @@ -0,0 +1,84 @@ +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local gears = require("gears") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE +local Pango = require("lgi").Pango --DOC_HIDE + +-- Beautiful fake get_font --DOC_HIDE +local f = Pango.FontDescription.from_string("monospace 10") --DOC_HIDE +beautiful.get_font = function() return f end --DOC_HIDE + +-- Fake beautiful theme --DOC_HIDE +beautiful.fg_focus = "#ff9800" --DOC_HIDE +beautiful.bg_focus = "#b9214f" --DOC_HIDE + + local styles = {} + local function rounded_shape(size, partial) + if partial then + return function(cr, width, height) + gears.shape.partially_rounded_rect(cr, width, height, + false, true, false, true, 5) + end + else + return function(cr, width, height) + gears.shape.rounded_rect(cr, width, height, size) + end + end + end + styles.month = { padding = 5, + bg_color = "#555555", + border_width = 2, + shape = rounded_shape(10) + } + styles.normal = { shape = rounded_shape(5) } + styles.focus = { fg_color = "#000000", + bg_color = "#ff9800", + markup = function(t) return '' .. t .. '' end, + shape = rounded_shape(5, true) + } + styles.header = { fg_color = "#de5e1e", + markup = function(t) return '' .. t .. '' end, + shape = rounded_shape(10) + } + styles.weekday = { fg_color = "#7788af", + markup = function(t) return '' .. t .. '' end, + shape = rounded_shape(5) + } + + local function decorate_cell(widget, flag, date) + if flag=="monthheader" and not styles.monthheader then + flag = "header" + end + local props = styles[flag] or {} + if props.markup and widget.get_text and widget.set_markup then + widget:set_markup(props.markup(widget:get_text())) + end + + -- Change bg color for weekends + local d = {year=date.year, month=(date.month or 1), day=(date.day or 1)} + local weekday = tonumber(os.date("%w", os.time(d))) + local default_bg = (weekday==0 or weekday==6) and "#232323" or "#383838" + + local ret = wibox.widget { + { + widget, + margins = (props.padding or 2) + (props.border_width or 0), + widget = wibox.container.margin + }, + shape = props.shape, + shape_border_color = props.border_color or "#b9214f", + shape_border_width = props.border_width or 0, + fg = props.fg_color or "#999999", + bg = props.bg_color or default_bg, + widget = wibox.container.background + } + return ret + end + + local cal = wibox.widget { + date = os.date("*t"), + fn_embed = decorate_cell, + widget = wibox.widget.calendar.month + } + +parent:add(cal) --DOC_HIDE diff --git a/tests/examples/wibox/widget/calendar/font.lua b/tests/examples/wibox/widget/calendar/font.lua new file mode 100644 index 00000000..5c42571f --- /dev/null +++ b/tests/examples/wibox/widget/calendar/font.lua @@ -0,0 +1,17 @@ +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE +local Pango = require("lgi").Pango --DOC_HIDE + +-- Beautiful fake get_font --DOC_HIDE +local f = Pango.FontDescription.from_string("sans 12") --DOC_HIDE +beautiful.get_font = function() return f end --DOC_HIDE + +-- Fake beautiful theme --DOC_HIDE +beautiful.fg_focus = "#ff9800" --DOC_HIDE +beautiful.bg_focus = "#b9214f" --DOC_HIDE + + local cal = wibox.widget.calendar.month( + os.date("*t"), "sans 12") + +parent:add(cal) --DOC_HIDE diff --git a/tests/examples/wibox/widget/calendar/long_weekdays.lua b/tests/examples/wibox/widget/calendar/long_weekdays.lua new file mode 100644 index 00000000..a4a671bc --- /dev/null +++ b/tests/examples/wibox/widget/calendar/long_weekdays.lua @@ -0,0 +1,21 @@ +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE +local Pango = require("lgi").Pango --DOC_HIDE + +-- Beautiful fake get_font --DOC_HIDE +local f = Pango.FontDescription.from_string("monospace 10") --DOC_HIDE +beautiful.get_font = function() return f end --DOC_HIDE + +-- Fake beautiful theme --DOC_HIDE +beautiful.fg_focus = "#ff9800" --DOC_HIDE +beautiful.bg_focus = "#b9214f" --DOC_HIDE + + local cal = wibox.widget { + date = os.date("*t"), + font = "Monospace 10", + long_weekdays = true, + widget = wibox.widget.calendar.month + } + +parent:add(cal) --DOC_HIDE diff --git a/tests/examples/wibox/widget/calendar/month.lua b/tests/examples/wibox/widget/calendar/month.lua new file mode 100644 index 00000000..38167f28 --- /dev/null +++ b/tests/examples/wibox/widget/calendar/month.lua @@ -0,0 +1,51 @@ +local parent = ... --DOC_HIDE_ALL +local wibox = require("wibox") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE +local Pango = require("lgi").Pango --DOC_HIDE + +-- Beautiful fake get_font --DOC_HIDE +local f = Pango.FontDescription.from_string("monospace 10") --DOC_HIDE +beautiful.get_font = function() return f end --DOC_HIDE + +-- Fake beautiful theme --DOC_HIDE +beautiful.fg_focus = "#ff9800" --DOC_HIDE +beautiful.bg_focus = "#b9214f" --DOC_HIDE + +local date = os.date("*t") --DOC_HIDE + + local w = wibox.widget { + { + { + { + text = '{day='..date.day..', month='..date.month..',\n year='..date.year..'}', + align = 'center', + widget = wibox.widget.textbox + }, + border_width = 2, + bg = beautiful.bg_normal, + widget = wibox.container.background + }, + wibox.widget.calendar.month({day=date.day, month=date.month, year=date.year}), + spacing = 10, + widget = wibox.layout.fixed.vertical + }, + { + { + { + text = '{month='..date.month..',\n year='..date.year..'}', + align = 'center', + widget = wibox.widget.textbox + }, + border_width = 2, + bg = beautiful.bg_normal, + widget = wibox.container.background + }, + wibox.widget.calendar.month({month=date.month, year=date.year}), + spacing = 10, + widget = wibox.layout.fixed.vertical + }, + spacing = 20, + widget = wibox.layout.flex.horizontal + } + +parent:add(w) --DOC_HIDE diff --git a/tests/examples/wibox/widget/calendar/start_sunday.lua b/tests/examples/wibox/widget/calendar/start_sunday.lua new file mode 100644 index 00000000..346b587b --- /dev/null +++ b/tests/examples/wibox/widget/calendar/start_sunday.lua @@ -0,0 +1,21 @@ +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE +local Pango = require("lgi").Pango --DOC_HIDE + +-- Beautiful fake get_font --DOC_HIDE +local f = Pango.FontDescription.from_string("monospace 10") --DOC_HIDE +beautiful.get_font = function() return f end --DOC_HIDE + +-- Fake beautiful theme --DOC_HIDE +beautiful.fg_focus = "#ff9800" --DOC_HIDE +beautiful.bg_focus = "#b9214f" --DOC_HIDE + + local cal = wibox.widget { + date = os.date("*t"), + font = "Monospace 10", + start_sunday = true, + widget = wibox.widget.calendar.month + } + +parent:add(cal) --DOC_HIDE diff --git a/tests/examples/wibox/widget/calendar/week_numbers.lua b/tests/examples/wibox/widget/calendar/week_numbers.lua new file mode 100644 index 00000000..b319a756 --- /dev/null +++ b/tests/examples/wibox/widget/calendar/week_numbers.lua @@ -0,0 +1,21 @@ +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE +local Pango = require("lgi").Pango --DOC_HIDE + +-- Beautiful fake get_font --DOC_HIDE +local f = Pango.FontDescription.from_string("monospace 10") --DOC_HIDE +beautiful.get_font = function() return f end --DOC_HIDE + +-- Fake beautiful theme --DOC_HIDE +beautiful.fg_focus = "#ff9800" --DOC_HIDE +beautiful.bg_focus = "#b9214f" --DOC_HIDE + + local cal = wibox.widget { + date = os.date("*t"), + font = "Monospace 10", + week_numbers = true, + widget = wibox.widget.calendar.month + } + +parent:add(cal) --DOC_HIDE diff --git a/tests/examples/wibox/widget/calendar/year.lua b/tests/examples/wibox/widget/calendar/year.lua new file mode 100644 index 00000000..4274a0e2 --- /dev/null +++ b/tests/examples/wibox/widget/calendar/year.lua @@ -0,0 +1,25 @@ +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE +local Pango = require("lgi").Pango --DOC_HIDE + +-- Beautiful fake get_font --DOC_HIDE +local f = Pango.FontDescription.from_string("monospace 10") --DOC_HIDE +beautiful.get_font = function() return f end --DOC_HIDE + +-- Fake beautiful theme --DOC_HIDE +beautiful.fg_focus = "#ff9800" --DOC_HIDE +beautiful.bg_focus = "#b9214f" --DOC_HIDE + + local cal = wibox.widget { + date = os.date("*t"), + font = "Monospace 8", + spacing = 2, + week_numbers = false, + start_sunday = false, + widget = wibox.widget.calendar.year + } + +parent:add(cal) --DOC_HIDE +local w,h = parent:fit({dpi=96}, 9999, 9999) --DOC_HIDE +return w+30, h --DOC_HIDE diff --git a/tests/examples/wibox/widget/defaults/calendar.lua b/tests/examples/wibox/widget/defaults/calendar.lua new file mode 100644 index 00000000..ea57daad --- /dev/null +++ b/tests/examples/wibox/widget/defaults/calendar.lua @@ -0,0 +1,16 @@ +local parent = ... --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE +local Pango = require("lgi").Pango --DOC_HIDE + +-- Beautiful fake get_font --DOC_HIDE +local f = Pango.FontDescription.from_string("monospace 10") --DOC_HIDE +beautiful.get_font = function() return f end --DOC_HIDE + +-- Fake beautiful theme --DOC_HIDE +beautiful.fg_focus = "#ff9800" --DOC_HIDE +beautiful.bg_focus = "#b9214f" --DOC_HIDE + + local cal = wibox.widget.calendar.month(os.date("*t")) + +parent:add(cal) --DOC_HIDE diff --git a/tests/test-awful-widget-calendar_popup.lua b/tests/test-awful-widget-calendar_popup.lua new file mode 100644 index 00000000..d432b5e7 --- /dev/null +++ b/tests/test-awful-widget-calendar_popup.lua @@ -0,0 +1,71 @@ +--- Test for awful.widget.calendar + +local runner = require("_runner") +local awful = require("awful") +local calendar = require("awful.widget.calendar_popup") + +local wa = awful.screen.focused().workarea + +local cmonth = calendar.month() +local cyear = calendar.year() +local current_date = os.date("*t") +local day, month, year = current_date.day, current_date.month, current_date.year + +local steps = { + -- Check center geometry + function(count) + if count == 1 then + cmonth:call_calendar(0, 'cc') + else + local geo = cmonth:geometry() + assert( math.abs((wa.x + wa.width/2.0) - (geo.x + geo.width/2.0)) < 2 ) + assert( math.abs((wa.y + wa.height/2.0) - (geo.y + geo.height/2.0)) < 2 ) + return true + end + end, + -- Check top-right geometry + function(count) + if count == 1 then + cmonth:call_calendar(0, 'tr') + else + local geo = cmonth:geometry() + assert(wa.x + wa.width == geo.x + geo.width) + assert(wa.y == geo.y) + return true + end + end, + -- Check visibility + function() + local v = cyear.visible + cyear:toggle() + assert(v == not cyear.visible) + return true + end, + -- Check current date + function() + local mdate = cmonth:get_widget():get_date() + assert(mdate.day==day and mdate.month==month and mdate.year==year) + local ydate = cyear:get_widget():get_date() + assert(ydate.year==year) + return true + end, + -- Check new date + function(count) + if count == 1 then + -- Increment + cmonth:call_calendar(1) + cyear:call_calendar(-1) + else + local mdate = cmonth:get_widget():get_date() + assert( mdate.day==nil and + ((mdate.month==month+1 and mdate.year==year) or (mdate.month==1 and mdate.year==year+1)) ) + local ydate = cyear:get_widget():get_date() + assert(ydate.year==year-1) + return true + end + end, + +} +runner.run_steps(steps) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80