Skip to content

Instantly share code, notes, and snippets.

@MiyamonY
Last active August 29, 2015 14:22
Show Gist options
  • Save MiyamonY/95e725b3af2cc92899a6 to your computer and use it in GitHub Desktop.
Save MiyamonY/95e725b3af2cc92899a6 to your computer and use it in GitHub Desktop.
gcc `pkg-config --cflags gtk+-3.0` -o test test.c `pkg-config --libs gtk+-3.0`
#include <stdlib.h>
#include <gtk/gtk.h>
#include <string.h>
#include <stdio.h>
static gboolean tick(gpointer buffer)
{
gchar str[100];
long time;
time = strtol(gtk_entry_buffer_get_text((GtkEntryBuffer *)buffer), NULL, 10);
if(time == 0){
system("aplay /usr/share/sounds/alsa/Front_Center.wav");
return FALSE;
}else{
/* g_print("%ld", time); */
sprintf(str, "%ld", time - 1);
gtk_entry_buffer_set_text(buffer, (const gchar *)str, strlen(str));
return TRUE;
}
}
static void set_tick_and_start(GtkWidget *widget,
gpointer data,
GtkEntry *entry)
{
GtkEntryBuffer *buffer;
buffer = gtk_entry_get_buffer(entry);
g_timeout_add(1, tick, buffer);
return;
};
static void activate(GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *box;
GtkWidget *box2;
GtkWidget *entry;
window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "Test");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(window), box);
button = gtk_button_new_with_label("Start");
/* g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_widget_destroy), window); */
gtk_container_add(GTK_CONTAINER(box), button);
box2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add(GTK_CONTAINER(box), box2);
entry = gtk_entry_new_with_buffer(gtk_entry_buffer_new("", 0));
gtk_container_add(GTK_CONTAINER(box2), entry);
gtk_container_add(GTK_CONTAINER(box2), gtk_label_new("ms"));
g_signal_connect(button, "clicked", G_CALLBACK(set_tick_and_start), entry);
gtk_widget_show_all(window);
return;
}
int main(int argc, char *argv[])
{
GtkApplication *app;
int status;
app = gtk_application_new("test.time", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}
#include <stdlib.h>
#include <gtk/gtk.h>
#include <string.h>
#include <stdio.h>
static long timer;
static gboolean tick(gpointer buffer)
{
gchar str[100];
if(timer == 0){
system("aplay /usr/share/sounds/alsa/Front_Center.wav");
return FALSE;
}else{
timer --;
return TRUE;
}
}
static void set_tick_and_start(GtkWidget *widget,
gpointer data,
GtkEntry *entry)
{
GtkEntryBuffer *buffer;
buffer = gtk_entry_get_buffer(entry);
timer = strtol(gtk_entry_buffer_get_text((GtkEntryBuffer *)buffer), NULL, 10);
g_timeout_add(1, tick, buffer);
return;
};
static void activate(GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *box;
GtkWidget *box2;
GtkWidget *entry;
window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "Test");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(window), box);
button = gtk_button_new_with_label("Start");
/* g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_widget_destroy), window); */
gtk_container_add(GTK_CONTAINER(box), button);
box2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add(GTK_CONTAINER(box), box2);
entry = gtk_entry_new_with_buffer(gtk_entry_buffer_new("", 0));
gtk_container_add(GTK_CONTAINER(box2), entry);
gtk_container_add(GTK_CONTAINER(box2), gtk_label_new("ms"));
g_signal_connect(button, "clicked", G_CALLBACK(set_tick_and_start), entry);
gtk_widget_show_all(window);
return;
}
int main(int argc, char *argv[])
{
GtkApplication *app;
int status;
app = gtk_application_new("test.time", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}
#! /usr/bin/env bash
sleep $1
aplay "/usr/share/sounds/alsa/Front_Center.wav"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment