Last active
March 7, 2020 15:04
-
-
Save idimiter/d2f1a6820c9cf9e867e6682fc13e39db to your computer and use it in GitHub Desktop.
Peek
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cassert> | |
#include <gtk/gtk.h> | |
#include <gdk/gdkscreen.h> | |
#include <gdk-pixbuf/gdk-pixbuf.h> | |
#include <cairo.h> | |
static GtkWidget *window; | |
static GdkPixbufAnimation *pixbuf_animation; | |
static GdkPixbufAnimationIter* animationIter; | |
static gboolean draw(GtkWidget */*window*/, cairo_t* cr, gpointer /*user_data*/) | |
{ | |
static uint gindex = 0; | |
static int fps_counter = 0; | |
auto pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(animationIter); | |
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); | |
cairo_paint(cr); | |
return false; | |
} | |
static void make_transparent(GtkWidget *widget) | |
{ | |
GdkScreen *screen = gtk_widget_get_screen(widget); | |
GdkVisual *visual = gdk_screen_get_rgba_visual(screen); | |
if (visual == nullptr) | |
{ | |
visual = gdk_screen_get_system_visual(screen); | |
} | |
gtk_widget_set_visual(widget, visual); | |
} | |
static gboolean timer(gpointer /*user_data*/) | |
{ | |
GTimeVal time; | |
g_get_current_time(&time); | |
gdk_pixbuf_animation_iter_advance(animationIter, &time); | |
g_timeout_add(gdk_pixbuf_animation_iter_get_delay_time(animationIter), timer, nullptr); | |
gtk_widget_queue_draw(window); | |
return FALSE; | |
} | |
int main(int ac, char** av) | |
{ | |
if ( fork() ) | |
{ | |
exit(0); // It's in your heeead, in your heeeead... :D | |
} | |
gtk_init(&ac, &av); | |
window = gtk_window_new(GTK_WINDOW_POPUP); | |
pixbuf_animation = gdk_pixbuf_animation_new_from_file("peek", nullptr); | |
if (!pixbuf_animation) | |
{ | |
exit(0); | |
} | |
GTimeVal time; | |
g_get_current_time(&time); | |
animationIter = gdk_pixbuf_animation_get_iter(pixbuf_animation, &time); | |
timer(nullptr); | |
gtk_window_set_title(GTK_WINDOW(window), "Never Gonna Give You Up!"); | |
gtk_window_set_decorated(GTK_WINDOW(window), false); | |
gtk_widget_set_app_paintable(window, true); | |
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), true); | |
gtk_window_set_skip_pager_hint(GTK_WINDOW(window), true); | |
GdkRectangle workarea = {0}; | |
gdk_monitor_get_workarea(gdk_display_get_primary_monitor(gdk_display_get_default()), &workarea); | |
auto imgw = gdk_pixbuf_animation_get_width (pixbuf_animation); | |
auto imgh = gdk_pixbuf_animation_get_height (pixbuf_animation); | |
gtk_window_resize(GTK_WINDOW(window), imgw, imgh); | |
gtk_window_move(GTK_WINDOW(window), workarea.width - imgw, workarea.height - imgh / 2 - 50); | |
make_transparent(window); | |
g_signal_connect(G_OBJECT(window), "delete-event", gtk_main_quit, nullptr); | |
g_signal_connect(G_OBJECT(window), "draw", G_CALLBACK(draw), nullptr); | |
gtk_widget_show_all(window); | |
gtk_main(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment