1a05542005-07-28Martin Nilsson /* -*- C -*- */ %{ #ifndef __NT__ #include <gdk/gdkprivate.h> #include <gdk/gdkx.h> #else #include <gdk/gdkprivate.h> #include <gdk/win32/gdkwin32.h> #endif /* The main stuff.. */
ba9e802006-02-27Martin Stjernholm int pgtk2_is_setup = 0, pgnome2_is_setup = 0;
1a05542005-07-28Martin Nilsson /* Not used in this file, really, but we need the require * 'preprocessor' stuff.. */
ba9e802006-02-27Martin Stjernholm int pgtk2_is_object_program(struct program *X)
1a05542005-07-28Martin Nilsson { #ifdef GTK_TYPE_TEXT_ITER
ba9e802006-02-27Martin Stjernholm  if ((X)==pgtk2_text_iter_program)
1a05542005-07-28Martin Nilsson  return 0; #endif #ifdef PANGO_TYPE_TAB_ARRAY
ba9e802006-02-27Martin Stjernholm  if ((X)==ppango2_tab_array_program)
1a05542005-07-28Martin Nilsson  return 0; #endif #ifdef GTK_TYPE_TEXT_ATTRIBUTES
ba9e802006-02-27Martin Stjernholm  if ((X)==pgtk2_text_attributes_program)
1a05542005-07-28Martin Nilsson  return 0; #endif #ifdef GTK_TYPE_TREE_ITER
ba9e802006-02-27Martin Stjernholm  if ((X)==pgtk2_tree_iter_program)
1a05542005-07-28Martin Nilsson  return 0; #endif #ifdef PANGO_TYPE_ATTR_LIST
ba9e802006-02-27Martin Stjernholm  if ((X)==ppango2_attr_list_program)
1a05542005-07-28Martin Nilsson  return 0; #endif #ifdef GTK_TYPE_TREE_PATH
ba9e802006-02-27Martin Stjernholm  if ((X)==pgtk2_tree_path_program)
1a05542005-07-28Martin Nilsson  return 0; #endif #ifdef PANGO_TYPE_FONT_DESCRIPTION
ba9e802006-02-27Martin Stjernholm  if ((X)==ppango2_font_description_program)
1a05542005-07-28Martin Nilsson  return 0; #endif return 1; } static void backend_callback(struct callback *_cb, void *arg, void *post_select) { if( !post_select ) { struct timeval timeout = current_time; timeout.tv_usec += 20000; if(timeout.tv_usec > 1000000) { timeout.tv_usec-=1000000; timeout.tv_sec+=1; } if (my_timercmp (&timeout, <, &next_timeout)) next_timeout = timeout; } else while(g_main_iteration( 0 ) ); } static struct callback *backend_cb; %} void parse_rc(string rc) //! Takes a string and reads it as a gtkrc file. { char *s; get_all_args("parse_rc",args,"%s",&s); gtk_rc_parse_string(s);
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  push_int(0); /* gtk_widget_propagate_default_style(); */ } GDK2.Window root_window() //! Returns the root window of the current display { static struct object *_pgtk_root_window;
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems( args );
1a05542005-07-28Martin Nilsson  if(_pgtk_root_window && _pgtk_root_window->prog ) { ref_push_object( _pgtk_root_window ); return; } else if( _pgtk_root_window ) free_object( _pgtk_root_window );
ba9e802006-02-27Martin Stjernholm  _pgtk_root_window = low_clone( pgdk2_window_program );
1a05542005-07-28Martin Nilsson  call_c_initializers( _pgtk_root_window ); /* ugly...*/ #ifdef GDK_ROOT_PARENT ((struct object_wrapper *)_pgtk_root_window->storage)->obj= (void *)GDK_ROOT_PARENT(); #else ((struct object_wrapper *)_pgtk_root_window->storage)->obj= (void *)&gdk_root_parent; #endif add_ref( _pgtk_root_window ); ref_push_object( _pgtk_root_window ); } require gnome;
506cbd2006-01-11Henrik Grubbström (Grubba) require gnomeui;
1a05542005-07-28Martin Nilsson  /* array(string) gnome_init(string app_id, string app_version, array(string) argv, int|void corba_init_flags) */ array(string) gnome_init(string app_id, string app_version, array(string) argv) //! Initializes the application. This sets up all of the GNOME //! internals and prepares them (gdk/gtk, session-management, //! triggers, sound, user preferences). If corba init flags are specified, //! corba initialization is done as well as gnome initialization. //! corba_init_flags is 0 or more of GNORBA_INIT_SERVER_FUNC (1), //! GNORBA_INIT_DISABLE_COOKIES (2) and GNORBA_INIT_CORBA_PRIO_HIGH (4) { gchar **data; char *id, *vers; gint argc; INT_TYPE flags=0;
ba9e802006-02-27Martin Stjernholm  if( pgtk2_is_setup )
1a05542005-07-28Martin Nilsson  Pike_error( "You should only call GTK2.setup_gtk() or Gnome.init() once\n"); switch( args ) { default: Pike_error( "Too few arguments, expected at least 3\n"); case 4: flags = PGTK_GETINT( Pike_sp-1 ); case 3: if( !PGTK_ISSTR( Pike_sp-args ) || !PGTK_ISSTR( Pike_sp-args+1 ) ) Pike_error("Illegal argument to Gnome.init()\n"); id = PGTK_GETSTR( Pike_sp-args ); vers = PGTK_GETSTR( Pike_sp-args+1 ); data = get_argv( &argc, args-2 ); }
ba9e802006-02-27Martin Stjernholm  pgnome2_is_setup = 1; pgtk2_is_setup = 1;
1a05542005-07-28Martin Nilsson  gtk_set_locale(); /* if( args == 4 ) applet_widget_init( id, vers, argc, data, NULL, flags, NULL ); else */
362a712006-01-09Marcus Comstedt  gnome_program_init(id,vers,LIBGNOMEUI_MODULE,argc,data,GNOME_PARAM_NONE);
1a05542005-07-28Martin Nilsson  backend_cb = (void *)add_backend_callback( backend_callback, 0, 0);
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  push_and_free_argv( data, argc, 1 ); } /* void applet_widget_gtk_main_quit() //! Exit from the applet_widget_gtk_main function on the next iteration. { gtk_main_quit(); } void applet_widget_gtk_main() //! Special corba main loop for gnome panel applets { applet_widget_gtk_main(); } */ endrequire;
506cbd2006-01-11Henrik Grubbström (Grubba) endrequire;
1a05542005-07-28Martin Nilsson 
3d76632005-11-03Lance Dillon require gnome_vfs; void gnome_vfs_init() //! Initialize gnome-vfs. Usually done automatically by gnome_init(). { gnome_vfs_init(); } endrequire;
1a05542005-07-28Martin Nilsson %{ static gchar **get_argv( int *argc_ret, int an ) { struct array *a; int argc; gchar **data; if( Pike_sp[-an].type != PIKE_T_ARRAY ) Pike_error("Expected array\n"); a = Pike_sp[-an].u.array; if (!a->size) Pike_error ("Expected array with at least one element.\n"); data=g_malloc0(sizeof(char *)*(a->size+1)); if (data==NULL)
32353e2005-12-30Martin Nilsson  Pike_error(msg_out_of_mem);
1a05542005-07-28Martin Nilsson  for( argc=0; argc<a->size; argc++ ) if (!PGTK_ISSTR(ITEM(a)+argc)) { g_free(data); Pike_error("Index %d in the array given as argv " "is not a valid string.\n", argc); } else data[argc] = PGTK_GETSTR( ITEM(a)+argc ); *argc_ret = argc; return data; } static void push_and_free_argv(gchar **data, int argc, int np) { int i; for (i=0; i<argc; i++) { PGTK_PUSH_GCHAR(data[i]); if (!np) PGTK_FREESTR(data[i]); } if (!np) f_aggregate(argc); else push_int(0); g_free(data); } %} array(string) setup_gtk(array(string)|void argv, int|void do_not_parse_rc) //! Initialize GTK, and all that comes with it. //! Also parses $HOME/.pgtkrc and $HOME/.gtkrc if they exists. //! The single argument, if supplied, is the argument array passed to //! the program. This is used to set default window titles etc. //! The second argument, if supplied, indicates that pike specific *rc files //! should <b>not</b> be parsed. //! <p> //! The most common usage is GTK2.setup_gtk(argv);</p> { gchar **data; int argc;
ba9e802006-02-27Martin Stjernholm  if (pgtk2_is_setup)
1a05542005-07-28Martin Nilsson  Pike_error("You should only call GTK2.setup_gtk() or Gnome.init() once\n"); if (args) data=get_argv(&argc,args); else { data=g_malloc(sizeof(char *)*2); if (data==NULL) SIMPLE_OUT_OF_MEMORY_ERROR("setup_gtk",sizeof(char *)*2); data[0]=g_strdup("Pike GTK"); argc=1; }
ba9e802006-02-27Martin Stjernholm  pgtk2_is_setup=1;
1a05542005-07-28Martin Nilsson  gtk_set_locale(); gtk_init(&argc,&data); g_type_init(); backend_cb=(void *)add_backend_callback(backend_callback,0,0);
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  push_and_free_argv(data,argc,0); } void flush() //! Flush GDK. Not normally needed, can be useful while doing calculations. { gdk_flush(); while(g_main_iteration( 0 ) );
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  push_int(0); } void low_flush() //! Flush, but do not process events. Not normally needed. { #ifndef __NT__ XFlush( GDK_DISPLAY() ); #else gdk_flush(); #endif
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems( args );
1a05542005-07-28Martin Nilsson  push_int( 0 ); } array(string) gtk_init(array(string)|void argc, int|void no_pgtkrc) //! Low level GTK init function (used by setup_gtk). //! This function is more or less equivalent to the C-GTK+ function gtk_init. //! setup_gtk does some extra things (such as parsing ~/.pgtkrc). {
ba9e802006-02-27Martin Stjernholm  pgtk2_setup_gtk( args );
1a05542005-07-28Martin Nilsson } void main() //! Start GTK in blocking mode.<br /> //! Doing this disables asynchronous I/O in pike.<br /> //! You can return -1 from main in pike to run GTK (and the rest of //! pike) in asynchronous mode. {
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  gtk_main(); } void main_quit() //! Exit from the gtk_main function on the next iteration. {
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  gtk_main_quit(); } int main_level() //! Return the current recursion depth. {
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  push_int( gtk_main_level() ); } int main_iteration_do(int block) //! Run one iteration in the mainloop. If block is true, wait for an //! event before returning. { INT_TYPE n; get_all_args( "gtk_main_iteration_do", args, "%i", &n );
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  push_int( g_main_iteration( n ) ); } int true() //! Always returns true. {
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  push_int(1); } int false() //! Always returns false. {
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  push_int(0); } void grab_add(GTK2.Widget widget) //! Grab a widget. { struct object *o; get_all_args("gtk_grab_add",args,"%o",&o); gtk_grab_add(GTK_WIDGET(get_gobject(o)));
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson } void grab_remove(GTK2.Widget widget) //! Remove the grab. { struct object *o; get_all_args("gtk_grab_remove",args,"%o",&o); gtk_grab_remove(GTK_WIDGET(get_gobject(o)));
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson } require x11; /* Low-level X11 related functions */ %{ #ifdef HAVE_XDPMS #include <X11/Xext.h> #include <X11/extensions/dpms.h> #endif /* screen-saver on/off status variables. * * TODO: Add an atexit() that restores the screensaver. */ static int timeout_save, dpms_off; %} void saver_disable( ) //! Disable the screensaver. //! This is a low-level X11 function, and thus only works when GDK uses X11 { int interval, prefer_blank, allow_exp;
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  XGetScreenSaver(GDK_DISPLAY(), &timeout_save, &interval, &prefer_blank, &allow_exp); if (timeout_save) XSetScreenSaver(GDK_DISPLAY(), 0, interval, prefer_blank, allow_exp); #ifdef HAVE_XDPMS if (DPMSQueryExtension(GDK_DISPLAY(), &interval, &interval)) { CARD16 state; DPMSInfo(GDK_DISPLAY(), &state, &dpms_off); if (dpms_off) DPMSDisable(mDisplay); /* monitor powersave off */ } #endif } void saver_enable( ) //! Enable the screensaver again after @[saver_disable] has been called. //! This is a low-level X11 function, and thus only works when GDK uses X11. {
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  if( timeout_save ) { int dummy, interval, prefer_blank, allow_exp; XGetScreenSaver(GDK_DISPLAY(), &dummy, &interval, &prefer_blank, &allow_exp); XSetScreenSaver(GDK_DISPLAY(), timeout_save, interval, prefer_blank, allow_exp); } #ifdef HAVE_XDPMS if (dpms_off) { DPMSEnable(mDisplay); /* monitor powersave on */ dpms_off=0; } #endif } void move_cursor( int dx, int dy ) //! Move the mouse-cursor dx,dy pixels, relative to it's current position. //! This will generate a normal motion event. //! //! Note that this is a low-level X11 function, and thus only works //! when GDK uses X11. { INT_TYPE x, y; get_all_args( "move_cursor", args, "%i%i", &x, &y );
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  XWarpPointer( GDK_DISPLAY(), None, None, 0, 0, 0, 0, x, y ); } void move_cursor_abs( GDK2.Window w, int dx, int dy ) //! Move the mouse-cursor to x,y, relative to the upper left corner of //! the specified window. This will generate a normal motion event. //! //! Note that this is a low-level X11 function, and thus only works //! when GDK uses X11. { INT_TYPE x, y; struct object *o; GdkWindowPrivate *priv; get_all_args("move_cursor_abs",args,"%o%i%i",&o,&x,&y); priv = (GdkWindowPrivate *)get_gdkobject( o, window ); if( !priv ) Pike_error("No window specified!\n"); XWarpPointer(GDK_DISPLAY(),None,priv->xwindow,0,0,0,0,x,y);
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson } endrequire; /* x11 */ require gtk22; array(mapping(string:mixed)) get_formats() //! Get information about the image formats supported. { GSList *gsl,*gs2; gchar **gca; int i=0,j,k;
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_setup(); pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  gs2=gsl=gdk_pixbuf_get_formats(); while (gs2) { i++; k=0;
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("name"));
1a05542005-07-28Martin Nilsson  push_text(gdk_pixbuf_format_get_name(gs2->data)); k++;
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("description"));
1a05542005-07-28Martin Nilsson  push_text(gdk_pixbuf_format_get_description(gs2->data)); k++;
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("mime_types"));
1a05542005-07-28Martin Nilsson  gca=gdk_pixbuf_format_get_mime_types(gs2->data); j=0; while (gca[j]) { PGTK_PUSH_GCHAR(gca[j]); j++; } f_aggregate(j); g_strfreev(gca); k++;
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("extensions"));
1a05542005-07-28Martin Nilsson  gca=gdk_pixbuf_format_get_extensions(gs2->data); j=0; while (gca[j]) { PGTK_PUSH_GCHAR(gca[j]); j++; } f_aggregate(j); g_strfreev(gca); k++; #ifdef HAVE_GTK26
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("disabled"));
1a05542005-07-28Martin Nilsson  push_int(gdk_pixbuf_format_is_disabled(gs2->data)); k++; #endif #ifdef HAVE_GTK26
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("license"));
1a05542005-07-28Martin Nilsson  push_text(gdk_pixbuf_format_get_license(gs2->data)); k++; #endif
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("is_writable"));
1a05542005-07-28Martin Nilsson  push_int(gdk_pixbuf_format_is_writable(gs2->data)); k++; #ifdef HAVE_GTK26
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("is_scalable"));
1a05542005-07-28Martin Nilsson  push_int(gdk_pixbuf_format_is_scalable(gs2->data)); k++; #endif f_aggregate_mapping(k*2); gs2=g_slist_next(gs2); } f_aggregate(i); g_slist_free(gsl); } endrequire; require gtk24; mapping(string:mixed) get_file_info(string filename) //! Parses an image file far enough to determine its format //! and size. { GdkPixbufFormat *gpf; gchar **gca; int j,k; char *filename; int width,height; get_all_args("get_file_info",args,"%s",&filename); gpf=gdk_pixbuf_get_file_info(filename,&width,&height);
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  k=0;
3d76632005-11-03Lance Dillon 
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("name"));
1a05542005-07-28Martin Nilsson  push_text(gdk_pixbuf_format_get_name(gpf)); k++;
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("description"));
1a05542005-07-28Martin Nilsson  push_text(gdk_pixbuf_format_get_description(gpf)); k++;
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("mime_types"));
1a05542005-07-28Martin Nilsson  gca=gdk_pixbuf_format_get_mime_types(gpf); j=0; while (gca[j]) { PGTK_PUSH_GCHAR(gca[j]); j++; } f_aggregate(j); g_strfreev(gca); k++;
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("extensions"));
1a05542005-07-28Martin Nilsson  gca=gdk_pixbuf_format_get_extensions(gpf); j=0; while (gca[j]) { PGTK_PUSH_GCHAR(gca[j]); j++; } f_aggregate(j); g_strfreev(gca); k++; #ifdef HAVE_GTK26
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("disabled"));
1a05542005-07-28Martin Nilsson  push_int(gdk_pixbuf_format_is_disabled(gpf)); k++; #endif #ifdef HAVE_GTK26
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("license"));
1a05542005-07-28Martin Nilsson  push_text(gdk_pixbuf_format_get_license(gpf)); k++; #endif
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("is_writable"));
1a05542005-07-28Martin Nilsson  push_int(gdk_pixbuf_format_is_writable(gpf)); k++; #ifdef HAVE_GTK26
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("is_scalable"));
1a05542005-07-28Martin Nilsson  push_int(gdk_pixbuf_format_is_scalable(gpf)); k++; #endif
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("width"));
1a05542005-07-28Martin Nilsson  push_int(width); k++;
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("height"));
1a05542005-07-28Martin Nilsson  push_int(height); k++; f_aggregate_mapping(k*2); } void set_default_icon(GDK2.Pixbuf icon) //! Sets an icon to be used as fallback for windows that haven't had set_icon() //! called on them from a pixbuf. { struct object *o1; get_all_args("set_default_icon",args,"%o",&o1); gtk_window_set_default_icon(GDK_PIXBUF(get_gobject(o1)));
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson } endrequire; require gtk22; void set_default_icon_from_file(string filename) //! Sets an icon to be used as fallback for windows that haven't had //! set_icon_list() called on them from a file on disk. { struct svalue *sv; get_all_args("set_default_icon_from_file",args,"%*",&sv);
3d76632005-11-03Lance Dillon 
1a05542005-07-28Martin Nilsson  gtk_window_set_default_icon_from_file(PGTK_GETSTR(sv),NULL);
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson } endrequire; require gtk26; void set_default_icon_name(string name) //! Sets an icon to be as fallback for windows that haven't had set_icon_list() //! called on them from a themed icon. { char *s; get_all_args("set_default_icon_name",args,"%s",&s); gtk_window_set_default_icon_name(s);
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson } endrequire; array(GTK2.Widget) list_toplevels() //! Returns a list of all existing toplevel windows. { GList *gl=gtk_window_list_toplevels(); GList *g2=gl; int i=0;
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  while (g2) { push_gobject(g2->&argc,args); //! Doing this disables asynchronous I/O in pike.<br /> //! You can return -1 from main in pike to run GTK (and the rest of //! pike) in asynchronous mode. { pgtk2_pop_n_elems(args); gtk_main(); } void main_quit() //! Exit from the gtk_main function on the next iteration. { pgtk2_pop_n_elems(args); gtk_main_quit();
ba9e802006-02-27Martin Stjernholm }
1a05542005-07-28Martin Nilsson  int main_level() //! Return the current recursion depth. { pgtk2_pop_n_elems(args); push_int( gtk_main_level() ); } int main_iteration_do(int block) //! Run one iteration in the mainloop. If block is true, wait for an
bcbd6c2006-02-01Lance Dillon //! event before returning. { INT_TYPE n; get_all_args( "gtk_main_iteration_do", args, "%i", &n );
1a05542005-07-28Martin Nilsson  pgtk2_pop_n_elems(args);
bcbd6c2006-02-01Lance Dillon  push_int( g_main_iteration( n ) ); } int true() //! Always returns true. { pgtk2_pop_n_elems(args); push_int(1); } int false() //! Always returns false. { pgtk2_pop_n_elems(args); push_int(0); } void grab_add(GTK2.Widget widget) //! Grab a widget.
ba9e802006-02-27Martin Stjernholm {
1a05542005-07-28Martin Nilsson  struct object *o; get_all_args("gtk_grab_add",args,"%o",&o);
bcbd6c2006-02-01Lance Dillon  gtk_grab_add(GTK_WIDGET(get_gobject(o)));
1a05542005-07-28Martin Nilsson  pgtk2_pop_n_elems(args); } void grab_remove(GTK2.Widget widget)
bcbd6c2006-02-01Lance Dillon //! Remove the grab. { struct object *o; get_all_args("gtk_grab_remove",args,"%o",&o); gtk_grab_remove(GTK_WIDGET(get_gobject(o))); pgtk2_pop_n_elems(args); }
ba9e802006-02-27Martin Stjernholm 
1a05542005-07-28Martin Nilsson 
bcbd6c2006-02-01Lance Dillon require x11;
1a05542005-07-28Martin Nilsson 
bcbd6c2006-02-01Lance Dillon /* Low-level X11 related functions */ %{
1a05542005-07-28Martin Nilsson #ifdef HAVE_XDPMS #include <X11/Xext.h>
bcbd6c2006-02-01Lance Dillon #include <X11/extensions/dpms.h> #endif /* screen-saver on/off status variables. * * TODO: Add an atexit() that restores the screensaver. */ static int timeout_save, dpms_off;
ba9e802006-02-27Martin Stjernholm %}
1a05542005-07-28Martin Nilsson 
bcbd6c2006-02-01Lance Dillon void saver_disable( )
1a05542005-07-28Martin Nilsson //! Disable the screensaver. //! This is a low-level X11 function, and thus only works when GDK uses X11 {
bcbd6c2006-02-01Lance Dillon  int interval, prefer_blank, allow_exp; pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  XGetScreenSaver(GDK_DISPLAY(),
bcbd6c2006-02-01Lance Dillon  &timeout_save, &interval, &prefer_blank, &allow_exp); if (timeout_save) XSetScreenSaver(GDK_DISPLAY(), 0, interval, prefer_blank, allow_exp); #ifdef HAVE_XDPMS if (DPMSQueryExtension(GDK_DISPLAY(), &interval, &interval)) { CARD16 state; DPMSInfo(GDK_DISPLAY(), &state, &dpms_off);
ba9e802006-02-27Martin Stjernholm  if (dpms_off)
1a05542005-07-28Martin Nilsson  DPMSDisable(mDisplay); /* monitor powersave off */ } #endif } void saver_enable( ) //! Enable the screensaver again after @[saver_disable] has been called. //! This is a low-level X11 function, and thus only works when GDK uses X11.
ba9e802006-02-27Martin Stjernholm {
1a05542005-07-28Martin Nilsson  pgtk2_pop_n_elems(args); if( timeout_save ) { int dummy, interval, prefer_blank, allow_exp; XGetScreenSaver(GDK_DISPLAY(), &dummy, &interval, &prefer_blank, &allow_exp); XSetScreenSaver(GDK_DISPLAY(), timeout_save, interval, prefer_blank, allow_exp); } #ifdef HAVE_XDPMS if (dpms_off) {
ba9e802006-02-27Martin Stjernholm  DPMSEnable(mDisplay); /* monitor powersave on */
1a05542005-07-28Martin Nilsson  dpms_off=0; }
cac4202005-12-17Marcus Comstedt #endif
1a05542005-07-28Martin Nilsson } void move_cursor( int dx, int dy )
ba9e802006-02-27Martin Stjernholm //! Move the mouse-cursor dx,dy pixels, relative to it's current position.
1a05542005-07-28Martin Nilsson //! This will generate a normal motion event. //! //! Note that this is a low-level X11 function, and thus only works
bcbd6c2006-02-01Lance Dillon //! when GDK uses X11. { INT_TYPE x, y; get_all_args( "move_cursor", args, "%i%i", &x, &y ); pgtk2_pop_n_elems(args); XWarpPointer( GDK_DISPLAY(), None, None, 0, 0, 0, 0, x, y ); } void move_cursor_abs( GDK2.Window w, int dx, int dy ) //! Move the mouse-cursor to x,y, relative to the upper left corner of //! the specified window. This will generate a normal motion event. //! //! Note that this is a low-level X11 function, and thus only works //! when GDK uses X11. { INT_TYPE x, y;
ba9e802006-02-27Martin Stjernholm  struct object *o;
bcbd6c2006-02-01Lance Dillon  GdkWindowPrivate *priv; get_all_args("move_cursor_abs",args,"%o%i%i",&o,&x,&y); priv = (GdkWindowPrivate *)get_gdkobject( o, window );
e34e262005-12-30Martin Nilsson  if( !priv ) Pike_error("No window specified!\n"); XWarpPointer(GDK_DISPLAY(),None,priv->xwindow,0,0,0,0,x,y); pgtk2_pop_n_elems(args); } endrequire; /* x11 */ require gtk22; array(mapping(string:mixed)) get_formats()
3c794f2005-12-29Martin Nilsson //! Get information about the image formats supported. { GSList *gsl,*gs2; gchar **gca; int i=0,j,k; pgtk2_verify_setup(); pgtk2_pop_n_elems(args); gs2=gsl=gdk_pixbuf_get_formats();
ef0ec72005-12-29Martin Nilsson  while (gs2) {
3c794f2005-12-29Martin Nilsson  i++; k=0; ref_push_string(_STR("name")); push_text(gdk_pixbuf_format_get_name(gs2->data)); k++; ref_push_string(_STR("description")); push_text(gdk_pixbuf_format_get_description(gs2->data)); k++; ref_push_string(_STR("mime_types")); gca=gdk_pixbuf_format_get_mime_types(gs2->data); j=0; while (gca[j]) {