Imported sm UPSTREAM_sm_0_1
authormail <mail@joachim-breitner.de>
Thu, 14 Jun 2007 12:58:09 +0000 (12:58 +0000)
committermail <mail@joachim-breitner.de>
Thu, 14 Jun 2007 12:58:09 +0000 (12:58 +0000)
into Darcs repository

Makefile [new file with mode: 0644]
sm.1 [new file with mode: 0644]
sm.c [new file with mode: 0644]
sm.py [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..3ead73c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+CFLAGS=-O3 `pkg-config pango gtk+-2.0 gdk-2.0 --cflags `
+LDFLAGS=-lm `pkg-config pango gtk+-2.0 gdk-2.0 --libs `
+
+all: sm
+
+sm: sm.c
+       gcc $(CFLAGS) $(LDFLAGS) $^ -o $@
+
+clean:
+       rm -f sm
+
diff --git a/sm.1 b/sm.1
new file mode 100644 (file)
index 0000000..35b685c
--- /dev/null
+++ b/sm.1
@@ -0,0 +1,37 @@
+.\"                                      Hey, EMACS: -*- nroff -*-
+.\" First parameter, NAME, should be all caps
+.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
+.\" other parameters are allowed: see man(7), man(1)
+.TH SM 1 "June 14, 2007"
+.\" Please adjust this date whenever revising the manpage.
+.\"
+.\" Some roff macros, for reference:
+.\" .nh        disable hyphenation
+.\" .hy        enable hyphenation
+.\" .ad l      left justify
+.\" .ad b      justify to both left and right margins
+.\" .nf        disable filling
+.\" .fi        enable filling
+.\" .br        insert line break
+.\" .sp <n>    insert n+1 empty lines
+.\" for manpage-specific macros, see man(7)
+.SH NAME
+sm \- Displays a short text fullscreen
+.SH SYNOPSIS
+.B sm
+.RI [ text ]
+.SH DESCRIPTION
+.B Screen Message 
+ will display a given multi-line message as large as
+ possible, fullscreen and black on white. You can specify the text either
+ when launching sm, or edit it while the program is running.
+.br
+
+.SH OPTIONS
+.TP
+.B text 
+Text to display at start up. Defaults to ":-)"
+
+.SH AUTHOR
+This manual page was written by Joachim Breitner <nomeata@debian.org>,
+for the Debian project (but may be used by others).
diff --git a/sm.c b/sm.c
new file mode 100644 (file)
index 0000000..396f6dc
--- /dev/null
+++ b/sm.c
@@ -0,0 +1,180 @@
+/*
+#     vlshow.c
+#     Copyright (C) 2006 Joachim Breitner
+#
+#     This program is free software; you can redistribute it and/or modify
+#     it under the terms of the GNU General Public License as published by
+#     the Free Software Foundation; either version 2 of the License, or
+#     (at your option) any later version.
+#
+#     This program is distributed in the hope that it will be useful,
+#     but WITHOUT ANY WARRANTY; without even the implied warranty of
+#     MERCHANTABILITY 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, write to the Free Software
+#     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+*/
+
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+#include <pango/pango.h>
+#include <string.h>
+#include <stdio.h>
+
+int min(int x, int y) {
+       return x < y ? x : y;
+}
+
+
+gboolean quality = TRUE;
+gboolean need_resize = TRUE;
+gboolean need_quick = TRUE;
+
+GtkWidget* window;
+GtkWidget* draw;
+GdkCursor *cursor;
+GtkWidget* quit;
+GtkWidget* tv;
+GtkSettings* settings;
+GtkTextBuffer* tb;
+PangoFontDescription *font;
+PangoLayout* layout;
+
+void realize(GtkWindow *window, GdkScreen *screen, gpointer data) {
+       gdk_window_set_cursor(draw->window, cursor);
+}
+
+void clear_text(GtkAccelGroup *accel, GObject *window, guint keyval,  GdkModifierType modifier) {
+       gtk_text_buffer_set_text(tb,"",-1);
+}
+
+char *get_text() {
+       GtkTextIter start, end;
+       gtk_text_buffer_get_start_iter(tb,&start);
+       gtk_text_buffer_get_end_iter(tb,&end);
+       return gtk_text_buffer_get_text(tb, &start, &end, FALSE);
+}
+
+
+void hq(gboolean q, gboolean force){
+       if (q != quality) 
+               if (q)
+                       gtk_settings_set_long_property(settings,"gtk-xft-antialias",1,"Hier halt");
+               else
+                       gtk_settings_set_long_property(settings,"gtk-xft-antialias",0,"Hier halt");
+       else
+               if (force)
+                       gtk_widget_queue_draw(draw);
+
+       quality = q;
+}
+
+void redraw() {
+       const char *text = pango_layout_get_text(layout);
+       if (strlen(text) > 0) {
+               GdkGC *gc = gtk_widget_get_style(draw)->fg_gc[GTK_STATE_NORMAL];
+               int w1, h1;
+               pango_layout_get_pixel_size(layout, &w1, &h1);
+               if (w1>0 && h1>0) {
+                       int w2 = draw->allocation.width;
+                       int h2 = draw->allocation.height;
+                       gdk_draw_layout(draw->window, gc, (w2-w1)/2,(h2-h1)/2,layout);
+                       hq(TRUE, FALSE);
+               }
+       }
+}
+
+void resize() {
+       int w1, h1, w2, h2;
+       pango_layout_get_pixel_size(layout, &w1, &h1);
+       if (w1>0 && h1>0) {
+               w2 = draw->allocation.width;
+               h2 = draw->allocation.height;
+               int s = pango_font_description_get_size(font);
+               s = min ((s*w2/w1), (s*h2/h1));
+               pango_font_description_set_size(font,s);
+               pango_layout_set_font_description(layout, font);
+               need_resize = FALSE;
+       }
+       else
+               need_resize = TRUE;
+}
+
+
+void newtext(char *text) {
+       pango_layout_set_text(layout, get_text(), -1);
+       resize();
+       hq(FALSE, TRUE);
+}
+
+int main(int argc, char **argv) {
+       gtk_init(&argc, &argv);
+
+       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
+       gtk_window_fullscreen(GTK_WINDOW(window));
+
+       settings = gtk_settings_get_default();
+       GdkColormap *colormap = gtk_widget_get_colormap(GTK_WIDGET(window));
+       GdkColor white;
+       gdk_colormap_alloc_color(colormap, &white, TRUE, TRUE);
+       gdk_color_parse("white", &white);
+       gtk_widget_modify_bg(GTK_WIDGET(window), GTK_STATE_NORMAL, &white);
+
+       draw = gtk_drawing_area_new();
+       gtk_widget_set_size_request(draw,400,400);
+       gtk_widget_modify_bg(draw, GTK_STATE_NORMAL, &white);
+       g_signal_connect(G_OBJECT(draw), "realize", G_CALLBACK(realize), NULL);
+
+       GdkPixmap *pixmap = gdk_pixmap_new(NULL, 1, 1, 1);
+       GdkColor color;
+       cursor = gdk_cursor_new_from_pixmap(pixmap, pixmap, &color, &color, 0, 0);
+
+       tv = gtk_text_view_new();
+       tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(tv));
+       
+       if (argc > 1)
+               //tb.set_text(" ".join(sys.argv[1:]))
+               gtk_text_buffer_set_text(tb, argv[1], -1);
+       else
+               gtk_text_buffer_set_text(tb, ":-)", -1);
+
+       quit = gtk_button_new_from_stock(GTK_STOCK_QUIT);
+       g_signal_connect(G_OBJECT(quit), "clicked", G_CALLBACK(gtk_main_quit), NULL);
+       gtk_widget_modify_bg(quit, GTK_STATE_NORMAL, &white);
+
+       GtkWidget *hbox = gtk_hbox_new(FALSE,0);
+       gtk_box_pack_start(GTK_BOX(hbox), tv,   TRUE,  TRUE,  0);
+       gtk_box_pack_start(GTK_BOX(hbox), quit, FALSE, FALSE, 0);
+
+       GtkWidget *vbox = gtk_vbox_new(FALSE,0);
+       gtk_box_pack_start(GTK_BOX(vbox), draw, TRUE,  TRUE,  0);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
+       gtk_container_add(GTK_CONTAINER(window), vbox);
+
+       font = pango_font_description_new();
+       pango_font_description_set_size(font, 20*PANGO_SCALE);
+
+       layout=  gtk_widget_create_pango_layout(draw,get_text());
+       pango_layout_set_font_description(layout, font);
+       pango_layout_set_alignment(layout,PANGO_ALIGN_CENTER);
+
+       GtkAccelGroup *accel = gtk_accel_group_new();
+       guint key;
+       GdkModifierType mod;
+       gtk_accelerator_parse("<Ctrl>Q", &key, &mod);
+       gtk_accel_group_connect(accel, key, mod, 0, g_cclosure_new(G_CALLBACK(gtk_main_quit), NULL, NULL));
+       gtk_accelerator_parse("Escape", &key, &mod);
+       gtk_accel_group_connect(accel, key, mod, 0, g_cclosure_new(G_CALLBACK(clear_text), NULL, NULL));
+       gtk_window_add_accel_group(GTK_WINDOW(window), accel);
+       gtk_widget_show_all(window);
+
+       g_signal_connect(G_OBJECT(draw), "configure-event", G_CALLBACK(resize), NULL);
+       g_signal_connect(G_OBJECT(draw), "expose-event", G_CALLBACK(redraw), NULL);
+       g_signal_connect(G_OBJECT(tb), "changed", G_CALLBACK(newtext), NULL);
+
+       gtk_main();
+}
diff --git a/sm.py b/sm.py
new file mode 100644 (file)
index 0000000..d94c86b
--- /dev/null
+++ b/sm.py
@@ -0,0 +1,139 @@
+#!/usr/bin/python
+# encoding:utf8
+
+#     vlshow.py
+#     Copyright (C) 2006 Joachim Breitner
+#
+#     This program is free software; you can redistribute it and/or modify
+#     it under the terms of the GNU General Public License as published by
+#     the Free Software Foundation; either version 2 of the License, or
+#     (at your option) any later version.
+#
+#     This program is distributed in the hope that it will be useful,
+#     but WITHOUT ANY WARRANTY; without even the implied warranty of
+#     MERCHANTABILITY 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, write to the Free Software
+#     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+import pango
+import sys
+import gobject
+
+window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+window.set_decorated(False)
+window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
+window.fullscreen()
+
+settings = gtk.settings_get_default()
+
+draw = gtk.DrawingArea()
+draw.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
+draw.set_size_request(400,300)
+
+pixmap = gtk.gdk.Pixmap(None, 1, 1, 1)
+color = gtk.gdk.Color()
+cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0)
+
+
+tv = gtk.TextView()
+tb = tv.get_buffer()
+
+def get_text():
+       return tb.get_text(tb.get_start_iter(), tb.get_end_iter())
+
+if len(sys.argv) > 1:
+       tb.set_text(" ".join(sys.argv[1:]))
+else:
+       tb.set_text(";-)")
+
+quit = gtk.Button(stock=gtk.STOCK_QUIT)
+quit.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
+quit.connect("clicked",gtk.main_quit)
+
+hbox = gtk.HBox()
+hbox.pack_start(tv, expand=True, fill=True)
+hbox.pack_start(quit,  expand=False,fill=False)
+
+vbox = gtk.VBox()
+vbox.pack_start(draw, expand=True, fill=True)
+vbox.pack_start(hbox, expand=False, fill=False)
+window.add(vbox)
+
+font = pango.FontDescription()
+font.set_size(60*pango.SCALE)
+layout = draw.create_pango_layout(get_text())
+layout.set_font_description(font)
+layout.set_alignment(pango.ALIGN_CENTER)
+
+
+accel = gtk.AccelGroup()
+key, mod = gtk.accelerator_parse("<Ctrl>Q")
+accel.connect_group(key, mod, 0, gtk.main_quit)
+key, mod = gtk.accelerator_parse("Escape")
+#accel.connect_group(key, mod, 0, gtk.main_quit)
+#key, mod = gtk.accelerator_parse("<Ctrl>C")
+accel.connect_group(key, mod, 0, (lambda x,y,z,v: tb.set_text("")))
+window.add_accel_group(accel)
+
+window.show_all()
+
+need_resize=True
+need_quick=True
+
+def resize(w=None,rect=None):
+       global need_resize
+       draw.window.set_cursor(cursor)
+       (w1,h1) = layout.get_pixel_size()
+       if h1>0 and w1>0:
+               (x,y,w2,h2) = draw.get_allocation()
+               s = font.get_size()
+               s = min ( int (s*w2/w1), int (s*h2/h1) )
+               font.set_size(s)
+               layout.set_font_description(font)
+               need_resize=False
+       else:
+               need_resize=True
+
+def redraw(w=None,e=None):
+       global need_resize, need_quick
+       if layout.get_text(): # Fails for empty lines :-(
+               gc = draw.get_style().fg_gc[gtk.STATE_NORMAL]
+               (w1,h1) = layout.get_pixel_size()
+               if h1>0 and w1>0:
+                       (x,y,w2,h2) = draw.get_allocation()
+                       draw.window.draw_layout(gc,(w2-w1)/2,(h2-h1)/2,layout)
+                       hq(True)
+
+quality = False
+def hq(q,force=False):
+       global quality
+       if q != quality:
+               if q:
+                       settings.set_long_property("gtk-xft-antialias",1,"Hier halt")
+               else:
+                       settings.set_long_property("gtk-xft-antialias",0,"Hier halt")
+       else:
+               if force:
+                       draw.queue_draw()
+
+       quality = q
+       return False
+
+def newtext(w):
+       global timeout_id
+       layout.set_text(get_text())
+       resize()
+       hq(False, True)
+
+draw.connect("configure-event", resize)
+draw.connect("expose-event", redraw)
+tb.connect("changed", newtext)
+
+gtk.main()