From 138604f74ea30864109bc8efaa0e90a0441a1761 Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Mon, 21 Dec 2009 17:27:56 +0000 Subject: [PATCH] Patch by German Arias . Allows to get icon placement from separate process. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29153 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 10 +++ Source/GNUmakefile | 1 + Source/GSIconManager.h | 36 +++++++++++ Source/GSIconManager.m | 142 +++++++++++++++++++++++++++++++++++++++++ Source/NSApplication.m | 16 +++-- Source/NSWindow.m | 18 +++++- 6 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 Source/GSIconManager.h create mode 100644 Source/GSIconManager.m diff --git a/ChangeLog b/ChangeLog index 20a2a7581..4066ec245 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-12-21 Fred Kiefer + + * Source/GSIconManager.h, + * Source/GSIconManager.m: New files. Allows to get icon placement + from separate process. + * Source/GNUmakefile: Add new file. + * Source/NSWindow.m, + * Source/NSApplication.m: Move icon handling into new file. + Patch by German Arias . + 2009-12-20 Eric Wasylishen * Source/NSColorWell.m: Draw a black-and-white pattern behind diff --git a/Source/GNUmakefile b/Source/GNUmakefile index 77d8af257..470b75986 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -217,6 +217,7 @@ GSLayoutManager.m \ GSTypesetter.m \ GSHorizontalTypesetter.m \ GSGormLoading.m \ +GSIconManager.m \ GSNibLoading.m \ GSTitleView.m \ GSToolTips.m \ diff --git a/Source/GSIconManager.h b/Source/GSIconManager.h new file mode 100644 index 000000000..7b1729061 --- /dev/null +++ b/Source/GSIconManager.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2009 Free Software Foundation, Inc. + + Written by: German Arias + Created: December 2009 + + This file is part of the GNUstep Project + + 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 3 + 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 library; see the file COPYING. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#import + +#import "AppKit/NSWindow.h" + +NSSize +GSGetIconSize(void); + +void +GSRemoveIcon(NSWindow *window); + +NSRect +GSGetIconFrame(NSWindow *window); diff --git a/Source/GSIconManager.m b/Source/GSIconManager.m new file mode 100644 index 000000000..c206bffcd --- /dev/null +++ b/Source/GSIconManager.m @@ -0,0 +1,142 @@ +/* Copyright (C) 2009 Free Software Foundation, Inc. + + Written by: German Arias + Created: December 2009 + + This file is part of the GNUstep Project + + 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 3 + 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 library; see the file COPYING. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#import +#import +#import + +#import +#import "AppKit/NSGraphics.h" +#import "GSIconManager.h" + +@protocol GSIconManager + - (NSRect) setWindow: (unsigned int)aWindowNumber appProcessId: (int)aProcessId; + - (void) removeWindow: (unsigned int)aWindowNumber; + - (NSSize) getSizeWindow; + - (id) retain; + - (void) release; +@end + +static BOOL verify = NO; +static id gsim = nil; +static int appId = 0; +static int iconCount = 0; + +static void +GSGetIconManager(void) +{ + if ([[NSUserDefaults standardUserDefaults] boolForKey: @"GSUseIconManager"]) + { + appId = [[NSProcessInfo processInfo] processIdentifier]; + + gsim = (id )[NSConnection rootProxyForConnectionWithRegisteredName: @"GSIconManager" + host: @""]; + + if (gsim == nil) + { + NSLog (@"Error: could not connect to server GSIconManager"); + } + + [gsim retain]; + } +} + +static inline void +checkVerify() +{ + if (!verify) + { + GSGetIconManager(); + verify = YES; + } +} + +NSSize +GSGetIconSize(void) +{ + NSSize iconSize; + + checkVerify(); + + if (gsim != nil) + { + iconSize = [gsim getSizeWindow]; + } + else + { + iconSize = [GSCurrentServer() iconSize]; + } + + return iconSize; +} + +void +GSRemoveIcon(NSWindow *window) +{ + checkVerify(); + + if (gsim != nil) + { + unsigned int winNum = 0; + + NSConvertWindowNumberToGlobal([window windowNumber], &winNum); + [gsim removeWindow: winNum]; + + iconCount--; + + if (iconCount == 0) + { + DESTROY(gsim); + verify = NO; + } + } +} + +NSRect +GSGetIconFrame(NSWindow *window) +{ + NSRect iconRect; + + checkVerify(); + + if (gsim != nil) + { + unsigned int winNum = 0; + + NSConvertWindowNumberToGlobal([window windowNumber], &winNum); + iconRect = [gsim setWindow: winNum + appProcessId: appId]; + + iconCount++; + } + else + { + NSSize iconSize; + + iconSize = [GSCurrentServer() iconSize]; + iconRect = NSMakeRect(0, 0, iconSize.height, iconSize.width); + } + + return iconRect; +} diff --git a/Source/NSApplication.m b/Source/NSApplication.m index d98c7ae4d..1a2228fe1 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -79,6 +79,7 @@ #include "AppKit/NSScreen.h" #include "AppKit/PSOperators.h" +#include "GSIconManager.h" #include "GNUstepGUI/GSDisplayServer.h" #include "GNUstepGUI/GSServicesManager.h" #include "GSGuiPrivate.h" @@ -466,7 +467,7 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) { NSSize iconSize, retSize; - iconSize = [GSCurrentServer() iconSize]; + iconSize = GSGetIconSize(); retSize.width = imageSize.width * iconSize.width / 64; retSize.height = imageSize.height * iconSize.height / 64; return retSize; @@ -477,7 +478,7 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) NSImage *tileImage; NSSize iconSize; - iconSize = [GSCurrentServer() iconSize]; + iconSize = GSGetIconSize(); /* _appIconInit will set our image */ dragCell = [[NSCell alloc] initImageCell: nil]; [dragCell setBordered: NO]; @@ -515,7 +516,7 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) - (void) drawRect: (NSRect)rect { - NSSize iconSize = [GSCurrentServer() iconSize]; + NSSize iconSize = GSGetIconSize(); [tileCell drawWithFrame: NSMakeRect(0, 0, iconSize.width, iconSize.height) inView: self]; @@ -3391,6 +3392,7 @@ struct _DelegateWrapper if (termination == NSTerminateNow) { + GSRemoveIcon(_app_icon_window); [self replyToApplicationShouldTerminate: YES]; } /* @@ -3668,8 +3670,7 @@ struct _DelegateWrapper - _appIconInit { NSAppIconView *iv; - NSSize iconSize = [GSCurrentServer() iconSize]; - NSRect iconRect = NSMakeRect(0, 0, iconSize.width, iconSize.height); + NSRect iconRect; unsigned mask = NSIconWindowMask; BOOL suppress; @@ -3682,12 +3683,15 @@ struct _DelegateWrapper } #endif - _app_icon_window = [[NSIconWindow alloc] initWithContentRect: iconRect + _app_icon_window = [[NSIconWindow alloc] initWithContentRect: NSZeroRect styleMask: mask backing: NSBackingStoreRetained defer: NO screen: nil]; + iconRect = GSGetIconFrame(_app_icon_window); + [_app_icon_window setFrame: iconRect display: YES]; + iv = [[NSAppIconView alloc] initWithFrame: iconRect]; [iv setImage: _app_icon]; [_app_icon_window setContentView: iv]; diff --git a/Source/NSWindow.m b/Source/NSWindow.m index a94c99229..b4b90f4f1 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -82,6 +82,7 @@ #include "GNUstepGUI/GSDisplayServer.h" #include "GSGuiPrivate.h" #include "GSToolTips.h" +#include "GSIconManager.h" #include "GSWindowDecorationView.h" #include "NSToolbarFrameworkPrivate.h" @@ -386,7 +387,7 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) { NSSize iconSize, retSize; - iconSize = [GSCurrentServer() iconSize]; + iconSize = GSGetIconSize(); retSize.width = imageSize.width * iconSize.width / 64; retSize.height = imageSize.height * iconSize.height / 64; return retSize; @@ -399,7 +400,7 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) NSImage *tileImage; NSSize iconSize; - iconSize = [GSCurrentServer() iconSize]; + iconSize = GSGetIconSize(); tileImage = [[GSCurrentServer() iconTileImage] copy]; [tileImage setScalesWhenResized: YES]; @@ -424,7 +425,7 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) - (void) drawRect: (NSRect)rect { - NSSize iconSize = [GSCurrentServer() iconSize]; + NSSize iconSize = GSGetIconSize(); [tileCell drawWithFrame: NSMakeRect(0, 0, iconSize.width, iconSize.height) inView: self]; @@ -2663,6 +2664,13 @@ resetCursorRectsForView(NSView *theView) _f.has_opened = NO; [NSApp removeWindowsItem: self]; [self orderOut: self]; + + if (_f.is_miniaturized == YES) + { + NSWindow *mini = GSWindowWithNumber(_counterpart); + GSRemoveIcon(mini); + } + RELEASE(pool); _f.has_closed = YES; RELEASE(self); @@ -2711,6 +2719,7 @@ resetCursorRectsForView(NSView *theView) { NSWindow *mini = GSWindowWithNumber(_counterpart); + GSRemoveIcon(mini); [mini orderOut: self]; } @@ -2808,7 +2817,10 @@ resetCursorRectsForView(NSView *theView) */ if (_counterpart != 0) { + NSRect iconRect; NSWindow *mini = GSWindowWithNumber(_counterpart); + iconRect = GSGetIconFrame(mini); + [mini setFrame: iconRect display: YES]; [mini orderFront: self]; } [nc postNotificationName: NSWindowDidMiniaturizeNotification