Skip to content

Instantly share code, notes, and snippets.

@mattn
Created February 15, 2010 12:01
Show Gist options
  • Save mattn/304596 to your computer and use it in GitHub Desktop.
Save mattn/304596 to your computer and use it in GitHub Desktop.
// g++ `pkg-config --cflags --libs gtk+-2.0` clipboard.cxx
// for windows: g++ -mms-bitfields -Ic:/gtk/include/gtk-2.0 -Ic:/gtk/lib/gtk-2.0/include -Ic:/gtk/include/atk-1.0 -Ic:/gtk/include/cairo -Ic:/gtk/include/pango-1.0 -Ic:/gtk/include/glib-2.0 -Ic:/gtk/lib/glib-2.0/include -Ic:/gtk/include/freetype2 -Ic:/gtk/include clipboard.cxx -Wl,-luuid -Lc:/gtk/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -limm32 -lshell32 -lole32 -latk-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpangoft2-1.0 -lpangowin32-1.0 -lgdi32 -lfreetype -lz -lfontconfig -lpango-1.0 -lm -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl
#include <iostream>
#include <sstream>
#include <gtk/gtk.h>
int main(int argc, char* argv[]) {
std::stringstream ss;
std::string line;
while (std::getline(std::cin, line))
ss << line << "\n";
gtk_init(&argc, &argv);
GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text(clipboard,
(gchar*) g_locale_to_utf8(ss.str().c_str(),
-1, NULL, NULL, NULL), -1);
gtk_clipboard_store(clipboard);
#ifdef _WIN32 /* verb */
gtk_main_iteration_do(TRUE);
#endif
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment