Cocoa: Move slightly towards modern Objective-C
Inspired by 9a9568212c.
This commit is contained in:
parent
4f5264277e
commit
cdbe2f13ca
@ -59,7 +59,7 @@ static NSUInteger getStyleMask(_GLFWwindow* window)
|
|||||||
CGDirectDisplayID displayIDForWindow(_GLFWwindow *w) {
|
CGDirectDisplayID displayIDForWindow(_GLFWwindow *w) {
|
||||||
NSWindow *nw = w->ns.object;
|
NSWindow *nw = w->ns.object;
|
||||||
NSDictionary *dict = [nw.screen deviceDescription];
|
NSDictionary *dict = [nw.screen deviceDescription];
|
||||||
NSNumber *displayIDns = [dict objectForKey:@"NSScreenNumber"];
|
NSNumber *displayIDns = dict[@"NSScreenNumber"];
|
||||||
if (displayIDns) return [displayIDns unsignedIntValue];
|
if (displayIDns) return [displayIDns unsignedIntValue];
|
||||||
return (CGDirectDisplayID)-1;
|
return (CGDirectDisplayID)-1;
|
||||||
}
|
}
|
||||||
@ -1275,7 +1275,7 @@ static void createMenuBar(void)
|
|||||||
|
|
||||||
for (i = 0; i < sizeof(nameKeys) / sizeof(nameKeys[0]); i++)
|
for (i = 0; i < sizeof(nameKeys) / sizeof(nameKeys[0]); i++)
|
||||||
{
|
{
|
||||||
id name = [bundleInfo objectForKey:nameKeys[i]];
|
id name = bundleInfo[nameKeys[i]];
|
||||||
if (name &&
|
if (name &&
|
||||||
[name isKindOfClass:[NSString class]] &&
|
[name isKindOfClass:[NSString class]] &&
|
||||||
![name isEqualToString:@""])
|
![name isEqualToString:@""])
|
||||||
|
|||||||
@ -49,7 +49,7 @@ find_app_name(void) {
|
|||||||
|
|
||||||
for (i = 0; i < sizeof(name_keys) / sizeof(name_keys[0]); i++)
|
for (i = 0; i < sizeof(name_keys) / sizeof(name_keys[0]); i++)
|
||||||
{
|
{
|
||||||
id name = [infoDictionary objectForKey:name_keys[i]];
|
id name = infoDictionary[name_keys[i]];
|
||||||
if (name &&
|
if (name &&
|
||||||
[name isKindOfClass:[NSString class]] &&
|
[name isKindOfClass:[NSString class]] &&
|
||||||
![name isEqualToString:@""])
|
![name isEqualToString:@""])
|
||||||
@ -60,7 +60,7 @@ find_app_name(void) {
|
|||||||
|
|
||||||
char** progname = _NSGetProgname();
|
char** progname = _NSGetProgname();
|
||||||
if (progname && *progname)
|
if (progname && *progname)
|
||||||
return [NSString stringWithUTF8String:*progname];
|
return @(*progname);
|
||||||
|
|
||||||
// Really shouldn't get here
|
// Really shouldn't get here
|
||||||
return @"kitty";
|
return @"kitty";
|
||||||
@ -171,7 +171,7 @@ cocoa_send_notification(PyObject *self UNUSED, PyObject *args) {
|
|||||||
NSUserNotification *n = [NSUserNotification new];
|
NSUserNotification *n = [NSUserNotification new];
|
||||||
NSImage *img = nil;
|
NSImage *img = nil;
|
||||||
if (path_to_image) {
|
if (path_to_image) {
|
||||||
NSString *p = [NSString stringWithUTF8String:path_to_image];
|
NSString *p = @(path_to_image);
|
||||||
NSURL *url = [NSURL fileURLWithPath:p];
|
NSURL *url = [NSURL fileURLWithPath:p];
|
||||||
img = [[NSImage alloc] initWithContentsOfURL:url];
|
img = [[NSImage alloc] initWithContentsOfURL:url];
|
||||||
[url release]; [p release];
|
[url release]; [p release];
|
||||||
@ -183,14 +183,14 @@ cocoa_send_notification(PyObject *self UNUSED, PyObject *args) {
|
|||||||
}
|
}
|
||||||
#define SET(x) { \
|
#define SET(x) { \
|
||||||
if (x) { \
|
if (x) { \
|
||||||
NSString *t = [NSString stringWithUTF8String:x]; \
|
NSString *t = @(x); \
|
||||||
n.x = t; \
|
n.x = t; \
|
||||||
[t release]; \
|
[t release]; \
|
||||||
}}
|
}}
|
||||||
SET(title); SET(subtitle); SET(informativeText);
|
SET(title); SET(subtitle); SET(informativeText);
|
||||||
#undef SET
|
#undef SET
|
||||||
if (identifier) {
|
if (identifier) {
|
||||||
n.userInfo = @{@"user_id": [NSString stringWithUTF8String:identifier]};
|
n.userInfo = @{@"user_id": @(identifier)};
|
||||||
}
|
}
|
||||||
[center deliverNotification:n];
|
[center deliverNotification:n];
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|||||||
@ -135,7 +135,7 @@ font_descriptor_from_python(PyObject *src) {
|
|||||||
|
|
||||||
#define SET(x, attr) \
|
#define SET(x, attr) \
|
||||||
t = PyDict_GetItemString(src, #x); \
|
t = PyDict_GetItemString(src, #x); \
|
||||||
if (t) attrs[(id)attr] = [NSString stringWithUTF8String:PyUnicode_AsUTF8(t)];
|
if (t) attrs[(id)attr] = @(PyUnicode_AsUTF8(t));
|
||||||
|
|
||||||
SET(family, kCTFontFamilyNameAttribute);
|
SET(family, kCTFontFamilyNameAttribute);
|
||||||
SET(style, kCTFontStyleNameAttribute);
|
SET(style, kCTFontStyleNameAttribute);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user