/******************************************************************************* *23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 * 10 20 30 40 50 60 70 80 * * count-down - An animated count-down rendition drawn with cairo looking like * the one seen in this video http://www.youtube.com/watch?v=Fuy2W6gY7hQ and * intended to be used in the kazam screenrecorder * * events.c - event-handling * * Copyright 2012 Mirco Müller * * Authors: * Mirco "MacSlow" Müller * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, 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 . * *******************************************************************************/ #include #include "events.h" #include "rendering.h" void screen_changed_cb (GtkWidget* widget, GdkScreen* oldScreen, gpointer data) { GdkScreen* screen = gtk_widget_get_screen (widget); /* not ref'ed*/ GdkVisual* visual = gdk_screen_get_rgba_visual (screen); /* not ref'ed*/ if (!visual) visual = gdk_screen_get_system_visual (screen); gtk_widget_set_visual (widget, visual); } gboolean configure_event_cb (GtkWidget* widget, GdkEventConfigure* event, gpointer data) { return FALSE; } gboolean draw_cb (GtkWidget* widget, cairo_t* cr, gpointer data) { static gint angle = 0; GTimer* timerId = (GTimer*) data; gint width = gtk_widget_get_allocated_width (widget); gint height = gtk_widget_get_allocated_height (widget); static cairo_surface_t* surface = NULL; if (!surface) { surface = create_drop_shadow (width, height, 10); /*cairo_surface_write_to_png (surface, "/tmp/surface.png");*/ } gdouble secondsf = g_timer_elapsed (timerId, NULL); gint seconds = ((gint) (trunc (secondsf)) % 5); render (cr, width, height, (gdouble) angle, 5 - seconds, surface); angle = (gint) ((trunc (secondsf) - secondsf) * 360.0); if (5 - seconds == 1) gtk_widget_set_opacity (widget, 1.0 + (trunc (secondsf) - secondsf)); else gtk_widget_set_opacity (widget, 1.0); return TRUE; } gboolean delete_event_cb (GtkWidget* widget, GdkEvent* event, gpointer data) { gtk_main_quit (); return FALSE; } gboolean timeout_cb (gpointer data) { GtkWidget* window = GTK_WIDGET (data); gtk_widget_queue_draw (window); return TRUE; }