Hi, this patch fixes bug 1996 completely.
http://www.freepascal.org/mantis/view.php?id=1996

Andrew
Index: lcl/interfaces/gtk/gtkcallback.inc
===================================================================
--- lcl/interfaces/gtk/gtkcallback.inc  (revision 10122)
+++ lcl/interfaces/gtk/gtkcallback.inc  (working copy)
@@ -1030,6 +1030,13 @@
   SizeMsg: TLMSize;
   GtkWidth: LongInt;
   GtkHeight: LongInt;
+  {$IFDEF HasX}
+  NetAtom: TGdkAtom;
+  AtomType: TGdkAtom;
+  AIndex, ADesktop: pguint;
+  AFormat: gint;
+  ALength: gint;
+  {$ENDIF}
 begin
   Result := CallBackDefaultReturn;
 
@@ -1046,14 +1053,34 @@
         GtkHeight:=Widget^.Allocation.Height;
         if GtkHeight<0 then GtkHeight:=0;
         debugln('GTKWindowStateEventCB ',DbgSName(TObject(Data)),' ',dbgs(state^.new_window_state),' ',WidgetFlagsToString(Widget));
-        if (GDK_WINDOW_STATE_ICONIFIED and state^.new_window_state)>0 then
-          // the window is iconified, or the user switched to another desktop
-          // TODO: find out which one happened.
-          // The LCL interprets SIZEICONIC as minimizing by the user
-          // and thus minimizes the whole application.
-          SizeMsg.SizeType:=SIZENORMAL //SIZEICONIC
+        if ((GDK_WINDOW_STATE_ICONIFIED and state^.new_window_state)>0) then begin
+          {$IFDEF HasX}
+          NetAtom := gdk_atom_intern('_NET_WM_DESKTOP', True);
+          if NetAtom > 0 then begin
+            if gdk_property_get(Widget^.window, NetAtom, XA_CARDINAL,0, 4, 0, @AtomType, @AFormat, @ALength, @AIndex)
+            then begin
+
+              NetAtom := gdk_atom_intern('_NET_CURRENT_DESKTOP', True);
+              if gdk_property_get(gdk_get_default_root_window, NetAtom, XA_CARDINAL,0, 4, 0, @AtomType, @AFormat, @ALength, @ADesktop)
+              then if ADesktop^ <> AIndex^ then begin
+                g_free(ADesktop);
+                g_free(AIndex);
+                exit;
+              end
+              else begin
+                g_free(ADesktop);
+                g_free(AIndex);
+              end;
+            end;
+          end;
+          {$ENDIF}
+          SizeMsg.SizeType:=SIZEICONIC;
+        end
         else if (GDK_WINDOW_STATE_MAXIMIZED and state^.new_window_state)>0 then
-          SizeMsg.SizeType:=SIZEFULLSCREEN
+        begin
+          if (state^.changed_mask and GDK_WINDOW_STATE_MAXIMIZED)=0 then Exit;
+          SizeMsg.SizeType:=SIZEFULLSCREEN;
+        end
         else
           SizeMsg.SizeType:=SIZENORMAL;
         with SizeMsg do
Index: lcl/interfaces/gtk/gtkobject.inc
===================================================================
--- lcl/interfaces/gtk/gtkobject.inc    (revision 10122)
+++ lcl/interfaces/gtk/gtkobject.inc    (working copy)
@@ -1174,6 +1174,16 @@
         else
           SizeType := SIZENORMAL or Size_SourceIsInterface;
         {$ELSE}
+        if LCLControl is TCustomForm then begin
+          // if the LCL gets an event without a State it resets it to SIZENORMAL
+          // so we send it the state it already is
+          case TCustomForm(LCLControl).WindowState of
+            wsNormal: SizeType := SIZENORMAL or Size_SourceIsInterface;
+            wsMinimized: SizeType := SIZEICONIC or Size_SourceIsInterface;
+            wsMaximized: SizeType := SIZEFULLSCREEN or Size_SourceIsInterface;
+          end;
+        end
+        else
         SizeType := Size_SourceIsInterface;
         {$ENDIF}
         Width := SmallInt(GtkWidth);

Reply via email to