Skip to content

Commit 1d5cbc9

Browse files
Merge pull request Whisky-App#3 from MythicApp/revert-2-revert-1-feat/icon-title-patch
Revert "Revert "Use exe title name""
2 parents 7b913c5 + ff03e5b commit 1d5cbc9

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed

dlls/winemac.drv/cocoa_app.h

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ enum {
6666
WineApplicationEventWakeQuery,
6767
};
6868

69+
/* Whisky hack #9 */
70+
#define kAppNameText @"%@ (Whi" \
71+
@"sky)"
72+
6973

7074
@class WineEventQueue;
7175
@class WineWindow;
@@ -128,6 +132,8 @@ enum {
128132

129133
NSImage* applicationIcon;
130134

135+
NSString* applicationName; /* Whisky hack #9 */
136+
131137
BOOL beenActive;
132138

133139
NSMutableSet* windowsBeingDragged;

dlls/winemac.drv/cocoa_app.m

+138
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ @interface WineApplicationController ()
9292
@property (retain, nonatomic) NSTimer* cursorTimer;
9393
@property (retain, nonatomic) NSCursor* cursor;
9494
@property (retain, nonatomic) NSImage* applicationIcon;
95+
@property (copy, nonatomic) NSString* applicationName; /* Whisky hack #9 */
9596
@property (readonly, nonatomic) BOOL inputSourceIsInputMethod;
9697
@property (retain, nonatomic) WineWindow* mouseCaptureWindow;
9798

@@ -108,6 +109,7 @@ @implementation WineApplicationController
108109
@synthesize keyboardType, lastFlagsChanged;
109110
@synthesize displaysTemporarilyUncapturedForDialog, temporarilyIgnoreResignEventsForDialog;
110111
@synthesize applicationIcon;
112+
@synthesize applicationName; /* Whisky hack #9 */
111113
@synthesize cursorFrames, cursorTimer, cursor;
112114
@synthesize mouseCaptureWindow;
113115
@synthesize lastSetCursorPositionTime;
@@ -201,6 +203,7 @@ - (void) dealloc
201203
[cursor release];
202204
[screenFrameCGRects release];
203205
[applicationIcon release];
206+
[applicationName release]; /* Whisky hack #9 */
204207
[clipCursorHandler release];
205208
[cursorTimer release];
206209
[cursorFrames release];
@@ -384,6 +387,14 @@ - (void) transformProcessToForeground:(BOOL)activateIfTransformed
384387
[self changeEditMenuKeyEquivalentsForWindow:[NSApp keyWindow]];
385388

386389
[NSApp setApplicationIconImage:self.applicationIcon];
390+
391+
/* Whisky hack #9 */
392+
// Set application name
393+
NSString* appName = [NSString stringWithFormat:kAppNameText, self.applicationName];
394+
bool success = [self setProcessName:appName];
395+
if (!success)
396+
NSLog(@"Failed to set process name to %@", appName);
397+
[appName release];
387398
}
388399
}
389400

@@ -833,6 +844,110 @@ - (void) sendDisplaysChanged:(BOOL)activating
833844
macdrv_release_event(event);
834845
}
835846

847+
/* Whisky hack #9 */
848+
- (BOOL) setProcessName:(NSString*)name
849+
{
850+
// Convert the name to a CFString
851+
CFStringRef cfName = (CFStringRef)name;
852+
853+
// Must be called on the main thread
854+
if (![NSThread isMainThread]) {
855+
NSLog(@"setProcessName: must be called on the main thread");
856+
return false;
857+
}
858+
859+
// New name can't be NULL or empty
860+
if (!cfName || CFStringGetLength(cfName) == 0) {
861+
NSLog(@"setProcessName: Invalid process name");
862+
return false;
863+
}
864+
865+
// Private types used in calls to launch services
866+
typedef CFTypeRef PrivateLaunchRef;
867+
typedef PrivateLaunchRef (*LSGetCurrentApplicationASNType)(void);
868+
typedef OSStatus (*LSSetApplicationInformationItemType)(
869+
int,
870+
PrivateLaunchRef,
871+
CFStringRef,
872+
CFStringRef,
873+
CFDictionaryRef
874+
);
875+
876+
// Static so we can reuse the same function pointers
877+
static bool initialized = false;
878+
static LSGetCurrentApplicationASNType getCurrentAppASNFunc = NULL;
879+
static LSSetApplicationInformationItemType setAppInfoFunc = NULL;
880+
static CFStringRef launchServicesDisplayNameKey = NULL;
881+
882+
// Initialize the function pointers
883+
if (!initialized) {
884+
initialized = true;
885+
886+
// Get the bundle for the LaunchServices framework
887+
CFBundleRef launchServicesBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices"));
888+
if (!launchServicesBundle) {
889+
NSLog(@"setProcessName: Failed to get LaunchServices bundle");
890+
return false;
891+
}
892+
893+
// Get the function pointers
894+
getCurrentAppASNFunc = (LSGetCurrentApplicationASNType)(
895+
CFBundleGetFunctionPointerForName(launchServicesBundle, CFSTR("_LSGetCurrentApplicationASN"))
896+
);
897+
if (!getCurrentAppASNFunc) {
898+
NSLog(@"setProcessName: Failed to get _LSGetCurrentApplicationASN in LaunchServices");
899+
return false;
900+
}
901+
setAppInfoFunc = (LSSetApplicationInformationItemType)(
902+
CFBundleGetFunctionPointerForName(launchServicesBundle, CFSTR("_LSSetApplicationInformationItem"))
903+
);
904+
if (!setAppInfoFunc) {
905+
NSLog(@"setProcessName: Failed to get _LSSetApplicationInformationItem in LaunchServices");
906+
return false;
907+
}
908+
909+
// Get the display name key
910+
const CFStringRef* displayNameKey = (const CFStringRef*)(
911+
CFBundleGetDataPointerForName(launchServicesBundle, CFSTR("_kLSDisplayNameKey"))
912+
);
913+
launchServicesDisplayNameKey = displayNameKey ? *displayNameKey : NULL;
914+
if (!launchServicesDisplayNameKey) {
915+
NSLog(@"setProcessName: Failed to get _kLSDisplayNameKey in LaunchServices");
916+
return false;
917+
}
918+
919+
// Force symbols to be loaded in the LaunchServices framework
920+
ProcessSerialNumber psn = {0, kCurrentProcess};
921+
GetCurrentProcess(&psn);
922+
}
923+
924+
// If any of the function pointers are NULL, we can't continue
925+
if (!getCurrentAppASNFunc || !setAppInfoFunc || !launchServicesDisplayNameKey) {
926+
NSLog(@"setProcessName: Failed to get all required LaunchServices functions");
927+
return false;
928+
}
929+
930+
// Get the current application's ASN
931+
PrivateLaunchRef currentAppASN = getCurrentAppASNFunc();
932+
933+
// Set the display name
934+
OSErr err = setAppInfoFunc(
935+
-2, // WebKit uses -2
936+
currentAppASN,
937+
launchServicesDisplayNameKey,
938+
cfName,
939+
NULL // Output parameter
940+
);
941+
942+
// Log any errors
943+
if (err != noErr) {
944+
NSLog(@"setProcessName: Failed to set display name: %d", err);
945+
return false;
946+
}
947+
948+
return true;
949+
}
950+
836951
// We can compare two modes directly using CFEqual, but that may require that
837952
// they are identical to a level that we don't need. In particular, when the
838953
// OS switches between the integrated and discrete GPUs, the set of display
@@ -1176,6 +1291,13 @@ - (void) setApplicationIconFromCGImageArray:(NSArray*)images
11761291
self.applicationIcon = nsimage;
11771292
}
11781293

1294+
/* Whisky hack #9 */
1295+
- (void) setApplicationName:(NSString*)name
1296+
{
1297+
[applicationName release];
1298+
applicationName = [name copy];
1299+
}
1300+
11791301
- (void) handleCommandTab
11801302
{
11811303
if ([NSApp isActive])
@@ -2634,6 +2756,22 @@ void macdrv_set_application_icon(CFArrayRef images, CFURLRef urlRef)
26342756
});
26352757
}
26362758

2759+
/* Whisky hack #9 */
2760+
/***********************************************************************
2761+
* macdrv_set_application_name
2762+
*
2763+
* Set the application name.
2764+
*/
2765+
void macdrv_set_application_name(CFStringRef name)
2766+
{
2767+
NSString* nsName = (NSString*)name;
2768+
2769+
OnMainThreadAsync(^{
2770+
WineApplicationController* controller = [WineApplicationController sharedController];
2771+
[controller setApplicationName:nsName];
2772+
});
2773+
}
2774+
26372775
/***********************************************************************
26382776
* macdrv_quit_reply
26392777
*/

dlls/winemac.drv/macdrv_cocoa.h

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ extern int macdrv_start_cocoa_app(unsigned long long tickcount) DECLSPEC_HIDDEN;
266266
extern void macdrv_window_rejected_focus(const struct macdrv_event *event) DECLSPEC_HIDDEN;
267267
extern void macdrv_beep(void) DECLSPEC_HIDDEN;
268268
extern void macdrv_set_application_icon(CFArrayRef images, CFURLRef url /* CrossOver Hack 13440 */) DECLSPEC_HIDDEN;
269+
extern void macdrv_set_application_name(CFStringRef name) DECLSPEC_HIDDEN; /* Whisky hack #9 */
269270
extern void macdrv_quit_reply(int reply) DECLSPEC_HIDDEN;
270271
extern int macdrv_using_input_method(void) DECLSPEC_HIDDEN;
271272
extern void macdrv_set_mouse_capture_window(macdrv_window window) DECLSPEC_HIDDEN;

dlls/winemac.drv/window.c

+30
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,34 @@ static void set_app_icon(void)
13551355
}
13561356
}
13571357

1358+
/* Whisky hack #9 */
1359+
/***********************************************************************
1360+
* set_app_name
1361+
*/
1362+
static void set_app_name(void)
1363+
{
1364+
WCHAR app_name[MAX_PATH];
1365+
DWORD len = GetModuleFileNameW(0, app_name, ARRAY_SIZE(app_name));
1366+
1367+
// Get offset to the last backslash
1368+
DWORD last_char_pos = 0;
1369+
for (DWORD i = 0; i < len; i++)
1370+
{
1371+
if (app_name[i] == '\\')
1372+
last_char_pos = i;
1373+
}
1374+
1375+
if (len && len < ARRAY_SIZE(app_name))
1376+
{
1377+
CFStringRef name = CFStringCreateWithCharacters(NULL, app_name + last_char_pos + 1, len - last_char_pos - 1);
1378+
if (name)
1379+
{
1380+
macdrv_set_application_name(name);
1381+
CFRelease(name);
1382+
}
1383+
}
1384+
}
1385+
13581386

13591387
/**********************************************************************
13601388
* set_capture_window_for_move
@@ -1661,6 +1689,8 @@ BOOL macdrv_CreateDesktopWindow(HWND hwnd)
16611689
}
16621690

16631691
set_app_icon();
1692+
/* Whisky hack #9 */
1693+
set_app_name();
16641694
return TRUE;
16651695
}
16661696

0 commit comments

Comments
 (0)