Create a gist now

Instantly share code, notes, and snippets.

diff --git a/src/frame.c b/src/frame.c
index 5915c00..e353b7a 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -114,6 +114,9 @@ Lisp_Object Qwindow_id;
#ifdef HAVE_X_WINDOWS
Lisp_Object Qouter_window_id;
#endif
+#ifdef HAVE_NS
+Lisp_Object Qns_window_id;
+#endif
Lisp_Object Qparent_id;
Lisp_Object Qtitle, Qname;
Lisp_Object Qexplicit_name;
@@ -3261,6 +3264,11 @@ x_report_frame_params (f, alistptr)
store_in_alist (alistptr, Qouter_window_id,
build_string (buf));
#endif
+#ifdef HAVE_NS
+ sprintf (buf, "%ld", (long) FRAME_CG_WINDOW (f));
+ store_in_alist (alistptr, Qns_window_id,
+ build_string (buf));
+#endif
store_in_alist (alistptr, Qicon_name, f->icon_name);
FRAME_SAMPLE_VISIBILITY (f);
store_in_alist (alistptr, Qvisibility,
@@ -4465,6 +4473,10 @@ syms_of_frame ()
Qouter_window_id = intern_c_string ("outer-window-id");
staticpro (&Qouter_window_id);
#endif
+#ifdef HAVE_NS
+ Qns_window_id = intern_c_string ("ns-window-id");
+ staticpro (&Qns_window_id);
+#endif
Qparent_id = intern_c_string ("parent-id");
staticpro (&Qparent_id);
Qx = intern_c_string ("x");
diff --git a/src/nsterm.h b/src/nsterm.h
index 77d1ad8..73367fc 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -595,6 +595,7 @@ struct x_output
#define FRAME_X_OUTPUT(f) ((f)->output_data.ns)
#define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
#define FRAME_X_WINDOW(f) ((f)->output_data.ns->window_desc)
+#define FRAME_CG_WINDOW(f) (ns_cg_window(f))
/* This is the `Display *' which frame F is on. */
#define FRAME_NS_DISPLAY(f) (0)
@@ -770,6 +771,8 @@ extern unsigned long ns_get_rgb_color (struct frame *f,
float r, float g, float b, float a);
extern NSPoint last_mouse_motion_position;
+extern long ns_cg_window(struct frame *f);
+
#ifdef NS_IMPL_GNUSTEP
extern char gnustep_base_version[]; /* version tracking */
#endif
diff --git a/src/nsterm.m b/src/nsterm.m
index 4aade4a..360ef3a 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -6077,7 +6077,15 @@ ns_term_shutdown (int sig)
@end /* EmacsScroller */
+long ns_cg_window(struct frame *f)
+{
+ EmacsView *view = f->output_data.ns->view;
+ EmacsWindow *win = [view window];
+ CGWindowID wid = [win windowNumber];
+ //CGWindowID wid = HIWindowGetCGWindowID([win windowRef]);
+ return (long)wid;
+}
/* ==========================================================================
diff --git a/src/nsfns.m b/src/nsfns.m
index c77c40e..3890cd4 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -2098,7 +2098,84 @@ In case the execution fails, an error is signaled. */)
}
#endif
+#ifdef NS_IMPL_COCOA
+
+DEFUN ("frame-ns-workspace", Fframe_ns_workspace,
+ Sframe_ns_workspace, 0, 1, 0,
+ doc: /* Get workspace of FRAME. */)
+ (frame)
+ Lisp_Object frame;
+{
+ char buf[16];
+ struct frame *f;
+
+ if (NILP (frame))
+ frame = selected_frame;
+ CHECK_FRAME (frame);
+ f = XFRAME (frame);
+
+ if (FRAME_WINDOW_P (f)) {
+ EmacsView *view = f->output_data.ns->view;
+ EmacsWindow *win = [view window];
+ CGWindowID wid = [win windowNumber];
+ //CGWindowID wid = HIWindowGetCGWindowID([win windowRef]);
+ NSInteger workspace = -1;
+
+ NSArray *windowList
+ = (NSArray*)CGWindowListCopyWindowInfo(kCGWindowListOptionAll, wid);
+
+ for (NSDictionary* entry in (NSArray*)windowList)
+ {
+ NSInteger windowNumber = [[entry objectForKey:(id)kCGWindowNumber] integerValue];
+ if (windowNumber == wid) {
+ workspace = [[entry objectForKey:(id)kCGWindowWorkspace] integerValue];
+ break;
+ }
+ }
+
+ [windowList release];
+
+
+ sprintf (buf, "%ld", (long) workspace);
+ return build_string (buf);
+ }
+
+ return Qnil;
+}
+
+
+typedef int CGSConnection;
+extern CGSConnection _CGSDefaultConnection(void);
+extern OSStatus CGSMoveWorkspaceWindowList(const CGSConnection connection,
+ CGWindowID *wids,
+ int count,
+ int toWorkspace);
+
+DEFUN ("set-frame-ns-workspace", Fset_frame_ns_workspace, Sset_frame_ns_workspace, 2, 2, 0,
+ doc: /* Set workspace of FRAME. */)
+ (frame, workspace)
+ Lisp_Object frame, workspace;
+{
+ register struct frame *f;
+
+ CHECK_LIVE_FRAME (frame);
+ CHECK_NUMBER (workspace);
+ f = XFRAME (frame);
+ if (FRAME_WINDOW_P (f)) {
+ EmacsView *view = f->output_data.ns->view;
+ EmacsWindow *win = [view window];
+ CGWindowID wid = [win windowNumber];
+ //CGWindowID wid = HIWindowGetCGWindowID([win windowRef]);
+ CGSConnection cid = _CGSDefaultConnection();
+
+ CGSMoveWorkspaceWindowList(cid, &wid, 1, XINT(workspace));
+ }
+
+ return Qt;
+}
+
+#endif
/* ==========================================================================
@@ -2672,6 +2749,8 @@ be used as the image of the icon representing the frame. */);
defsubr (&Sns_list_colors);
#ifdef NS_IMPL_COCOA
defsubr (&Sns_do_applescript);
+ defsubr (&Sframe_ns_workspace);
+ defsubr (&Sset_frame_ns_workspace);
#endif
defsubr (&Sxw_color_defined_p);
defsubr (&Sxw_color_values);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment