Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a calendar popup window when click Clock plugin item. #10

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
config.h.in~
configure~
m4/gettext.m4~
m4/host-cpu-c-abi.m4~
m4/iconv.m4~
m4/intlmacosx.m4~
m4/lib-ld.m4~
m4/lib-link.m4~
m4/lib-prefix.m4~
m4/po.m4~
m4/progtest.m4~
po/Makefile.in.in~
ABOUT-NLS
aclocal.m4
autom4te.cache
Expand Down
18 changes: 18 additions & 0 deletions docklets/Clock/ClockDockCalendar.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Plank;

namespace Docky
{
public class ClockDockCalendar : Gtk.Window {
public ClockDockCalendar () {
this.title = "Plank Clock Calendar";
this.border_width = 5;
this.set_default_size (300, 50);
this.set_position (Gtk.WindowPosition.MOUSE);
this.set_skip_taskbar_hint (true);
Gtk.Window.set_default_icon_name("calendar");

Gtk.Calendar calendar = new Gtk.Calendar ();
this.add (calendar);
}
}
}
34 changes: 27 additions & 7 deletions docklets/Clock/ClockDockItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Docky
uint timer_id = 0U;
int minute;
string current_theme;
ClockDockCalendar calendar;

/**
* {@inheritDoc}
Expand Down Expand Up @@ -88,14 +89,34 @@ namespace Docky

reset_icon_buffer ();
}

protected override AnimationType on_clicked (PopupButton button, Gdk.ModifierType mod, uint32 event_time)
{
int x, y;
if(calendar == null) {
calendar = new ClockDockCalendar ();
calendar.get_position(out x, out y);
calendar.move(x, y - 300);
calendar.destroy.connect(
() => {
calendar = null;
Gtk.main_quit();
}
);
calendar.show_all ();
} else {
calendar.present_with_time(event_time);
}
return AnimationType.NONE;
}

protected override void draw_icon (Surface surface)
{
unowned ClockPreferences prefs = (ClockPreferences) Prefs;

var now = new DateTime.now_local ();
if (prefs.ShowMilitary)
Text = now.format ("%a, %b %d %H:%M");
Text = now.format ("%F %T %A");
else
Text = now.format ("%a, %b %d %I:%M %p");

Expand All @@ -119,10 +140,10 @@ namespace Docky
unowned Cairo.Context cr = surface.Context;

// useful sizes
int timeSize = surface.Height / 4;
int dateSize = surface.Height / 5;
int timeSize = surface.Height / 3;
int dateSize = surface.Height / 4;
int ampmSize = surface.Height / 5;
int spacing = timeSize / 2;
int spacing = timeSize / 4;
int center = surface.Height / 2;

layout.set_width ((int) (surface.Width * Pango.SCALE));
Expand All @@ -138,12 +159,11 @@ namespace Docky
Pango.Rectangle ink_rect, logical_rect;
layout.get_pixel_extents (out ink_rect, out logical_rect);

int timeYOffset = prefs.ShowMilitary ? timeSize : timeSize / 2;
int timeXOffset = (surface.Width - ink_rect.width) / 2;
if (prefs.ShowDate)
cr.move_to (timeXOffset, timeYOffset);
cr.move_to (timeXOffset, timeSize / 2 - timeSize / 4);
else
cr.move_to (timeXOffset, timeYOffset + timeSize / 2);
cr.move_to (timeXOffset, timeSize - timeSize / 5);

Pango.cairo_layout_path (cr, layout);
cr.set_line_width (3);
Expand Down
1 change: 1 addition & 0 deletions docklets/Clock/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ libdocklet_clock_la_LTLIBRARIES = libdocklet-clock.la
libdocklet_clock_ladir = $(pkglibdir)/docklets

libdocklet_clock_la_VALASOURCES = \
ClockDockCalendar.vala \
ClockDockItem.vala \
ClockDocklet.vala \
ClockPreferences.vala \
Expand Down
56 changes: 53 additions & 3 deletions docklets/Desktop/DesktopDockItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace Docky
{
public class DesktopDockItem : DockletItem
{

Wnck.Screen screen;
Pango.Layout layout;
/**
* {@inheritDoc}
*/
Expand All @@ -33,13 +36,60 @@ namespace Docky

construct
{
Icon = "show-desktop;;resource://" + Docky.G_RESOURCE_PATH + "/icons/show-desktop.svg";
Text = _("Show Desktop");
screen = Wnck.Screen.get_default ();
unowned GLib.List<Wnck.Workspace> workspaces = screen.get_workspaces();
Wnck.Workspace current_workspace = workspaces.nth_data(screen.get_active_workspace().get_number());

layout = new Pango.Layout (Gdk.pango_context_get ());
var font_description = new Gtk.Style ().font_desc;
font_description.set_weight (Pango.Weight.BOLD);
layout.set_font_description (font_description);
layout.set_ellipsize (Pango.EllipsizeMode.NONE);

Icon = "Desktop";
Text = current_workspace.get_number().to_string();

screen.active_workspace_changed.connect_after (handle_workspace_changed);
}


protected override void draw_icon (Surface surface)
{
unowned Cairo.Context cr = surface.Context;
Pango.Rectangle ink_rect, logical_rect;

layout.set_width ((int) (surface.Width * Pango.SCALE));
layout.get_font_description ().set_absolute_size ((int) (surface.Width * Pango.SCALE));

if (Text.length > 1)
layout.set_text (Text.substring(0, 1), -1);
else
layout.set_text (Text, -1);

layout.get_pixel_extents (out ink_rect, out logical_rect);
int x_offset = (surface.Width - ink_rect.width) / 2;
int y_offset = -10;
cr.move_to(x_offset, y_offset);

Pango.cairo_layout_path (cr, layout);
cr.set_line_width (3);
cr.set_source_rgba (0, 0, 0, 0.5);
cr.stroke_preserve ();
cr.set_source_rgba (1, 1, 1, 0.8);
cr.fill ();
}

~DesktopDockItem ()
{
screen.active_workspace_changed.disconnect(handle_workspace_changed);
}

void handle_workspace_changed(Wnck.Screen screen, Wnck.Workspace? previous_workspace)
{
unowned GLib.List<Wnck.Workspace> workspaces = screen.get_workspaces();
Wnck.Workspace current_workspace = workspaces.nth_data(screen.get_active_workspace().get_number());
Text = current_workspace.get_number ().to_string ();
reset_icon_buffer();
}

protected override AnimationType on_clicked (PopupButton button, Gdk.ModifierType mod, uint32 event_time)
{
Expand Down