Tk Source Code

Attachment Details
Login
Overview

Artifact ID: c3ffa1f4fe13e4b93ab56278ceef61f8cb8973c593f7f0cb70b66b8622f17a21
Ticket: 94bdc4cc679bd6eef0c376ada03b286b15c0d138
Date: 2021-02-16 16:51:09
User: bll
Artifact Attached: d63e8b1f33494f1e54d9ca018b0297a74dc642d090be54364611fb95d2173d1f
Filename:tclmacnumscreens.m
Description:Objective C code to get the number of screens on mac.
Content:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
#import "Foundation/NSObject.h"
#include <MacTypes.h>
#import <Cocoa/Cocoa.h>

#define USE_TCL_STUBS

#include <stdlib.h>
#include <tcl.h>

int
Macnumscreens_Cmd (
  ClientData cd,
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *const objv[] )
{
  int   vol = 0;
  int   nscrn;
  int   rc = 0;
  int   set = 0;

  if (objc > 1) {
    Tcl_WrongNumArgs(interp, 1, objv, NULL);
    return TCL_ERROR;
  }

  NSArray *screens = [NSScreen screens];
  nscrn = [screens count];

  Tcl_SetObjResult(interp, Tcl_NewIntObj(nscrn));
  return TCL_OK;
}

int
Macnumscreens_Init (Tcl_Interp *interp)
{
  if (! Tcl_InitStubs(interp, TCL_VERSION, 0)) {
    return TCL_ERROR;
  }

  Tcl_CreateObjCommand (interp, "macnumscreens", Macnumscreens_Cmd, NULL, NULL);
  Tcl_PkgProvide (interp, "macnumscreens", "1.0");
  return TCL_OK;
}