; Module/File: Window_SetTransparentBackground_gtk3.pb ; Function: Set Window background transparency w/o decoration - Linux gtk3 ; Author: Omi ; Date: Jan. 02, 2017 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.40/5.5x/5.6x/5.7 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- ; http://zetcode.com/gfx/cairo/root/ ; https://stackoverflow.com/questions/3908565/how-to-make-gtk-window-background-transparent#3909283 EnableExplicit ImportC "" g_signal_connect(*instance, detailed_signal.p-utf8, *c_handler, *pdata, destroy= 0, flags= 0) As "g_signal_connect_data" gdk_cairo_create(*window) gdk_screen_get_rgba_visual(*screen.GdkScreen) gdk_screen_get_system_visual(*screen.GdkScreen) gtk_widget_get_window(*widget.GtkWidget) gtk_widget_set_tooltip_text(*widget, text.p-utf8) gtk_widget_set_visual(*widget.GtkWidget, *visual.GdkVisual) cairo_destroy(*cr) cairo_image_surface_create_from_png(filename.p-utf8) cairo_image_surface_get_height(*surface) cairo_image_surface_get_width(*surface) cairo_paint(*cr) cairo_scale(*cr, sx.d, sy.d) cairo_set_operator(*cr, op) cairo_set_source_rgba(*cr, red.d, green.d, blue.d, alpha.d) cairo_set_source_surface(*CairoContext, *surface, x.d, y.d) cairo_surface_destroy(*surface) EndImport ; Object constants #Win_Main = 0 #MainCont = 0 Enumeration cairo_operator_t #CAIRO_OPERATOR_CLEAR #CAIRO_OPERATOR_SOURCE EndEnumeration Global.i gEvent, gQuit Global *gSurface ProcedureC Callback_ScreenChanged(*widget.GtkWidget, *old_screen.GdkScreen, user_data) Protected *Screen.GdkScreen= gtk_widget_get_screen_(*widget) Protected *Visual.GdkVisual= gdk_screen_get_rgba_visual(*Screen) If Not *Visual *Visual = gdk_screen_get_system_visual(*Screen) EndIf gtk_widget_set_visual(*widget, *Visual) EndProcedure ProcedureC Callback_ExposeDraw(*widget.GtkWidget, *event.GdkEventExpose, user_data); user_data get #Window Protected *cr= gdk_cairo_create(gtk_widget_get_window(*widget)) cairo_set_source_rgba(*cr, 1.0, 1.0, 1.0, 0.0) cairo_set_operator(*cr, #CAIRO_OPERATOR_SOURCE) cairo_paint(*cr) ;scale a pic and show it ... cairo_scale(*cr, WindowWidth(user_data)/cairo_image_surface_get_width(*gSurface), WindowHeight(user_data)/cairo_image_surface_get_height(*gSurface)) cairo_set_source_surface(*cr, *gSurface, 0, 0) cairo_paint(*cr) cairo_destroy(*cr) ProcedureReturn #False EndProcedure Procedure Create_WinMain() If OpenWindow(#Win_Main, 300, 200, 400, 200, "Transp. window background gtk3", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible) Protected *Window= WindowID(#Win_Main) gtk_window_set_decorated_(*Window, #False) gtk_widget_set_app_paintable_(*Window, #True) gtk_widget_unrealize_(*Window) g_signal_connect(*Window, "draw", @Callback_ExposeDraw(), #Win_Main) g_signal_connect(*Window, "screen-changed", @Callback_ScreenChanged(), #Null) Callback_ScreenChanged(*Window, #Null, #Null) gtk_widget_show_all_(*Window) gtk_widget_set_tooltip_text(*Window, "[Esc] closes window") EndIf EndProcedure *gSurface= cairo_image_surface_create_from_png(#PB_Compiler_Home + "./logo.png") Create_WinMain() AddKeyboardShortcut(#Win_Main, #PB_Shortcut_Escape, #PB_Key_Escape) Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow cairo_surface_destroy(*gSurface) gQuit= #True Case #PB_Event_Menu If EventMenu() = #PB_Key_Escape gQuit= #True EndIf EndSelect Until gQuit ; IDE Options = PureBasic 5.70 LTS beta 3 (Linux - x64) ; CursorPosition = 10 ; FirstLine = 29 ; Folding = - ; EnableXP ; EnableUnicode