Esempio n. 1
0
    //////////////////////////////////////////////////////////////////////////
    ////                Win32 Event Listeners
    //////////////////////////////////////////////////////////////////////////
    LRESULT ViWmManager::HandleShellHook( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
    {
        if (msg != shellhookid)
            return DefWindowProc(hwnd, msg, wParam, lParam); 

        TilledWindow    *found;

        switch (wParam)
        {
        case HSHELL_WINDOWCREATED:
            if (TilledWindow::IsHandleTileable((HWND)lParam))
            {
                AddNode((HWND)lParam);
                ArrangeWindows();
                FocusCurrent();
                selectWindow( (HWND)lParam );
                _ASSERTE( _CrtCheckMemory() == TRUE );
            }
            break;

        case HSHELL_WINDOWDESTROYED:
            found = currentState.FindNode((HWND)lParam);
            if ( found )
            {
                for (size_t i = 0; i < currentLayout.size(); ++i)
                    LayoutTree::removeClean( currentLayout[i].layoutRoot, (HWND) lParam );

                currentState.RemoveNode((HWND)lParam, false);

                ArrangeWindows();
                FocusCurrent();
                _ASSERTE( _CrtCheckMemory() == TRUE );
            }
            break;

        case HSHELL_RUDEAPPACTIVATED:
        case HSHELL_WINDOWACTIVATED:
            if (globalManager->inDrag()) break;

            found = currentState.FindNode((HWND)lParam);
            if (found) {
                if (currentState.current) {
                    currentState.current->SetTransparency( globalManager->conf.idleTransparency() );
                }
                currentState.current = found;
                found->SetTransparency( 255 );
                selectWindow( (HWND)lParam );

                FocusCurrent();
            }
            _ASSERTE( _CrtCheckMemory() == TRUE );
            break;
        }
        return 0;
    }
Esempio n. 2
0
//-----------------------------------------------------------------------------
void CMRCFrameWndSizeDock::ArrangeFloatingBars(DWORD dwOrient)
//-----------------------------------------------------------------------------
{
	CObArray arrWnd;
	GetFloatingBars(arrWnd);
	ArrangeWindows(arrWnd, dwOrient);
}
Esempio n. 3
0
File: main.c Progetto: Jasu/HashTWM
void ToggleTag(unsigned short tag) {
  HWND hwnd = GetForegroundWindow();

  if (FindNode(hwnd, tag)) {
    RemoveNode(hwnd, tag);
    MinimizeWindow(hwnd);
  } else {
    AddNode(hwnd, tag);

    if (one_tag_per_window) {
      RemoveNode(hwnd, current_tag);
      MinimizeWindow(hwnd);
    }
  }

  ArrangeWindows();
}
Esempio n. 4
0
int main(int argc, char **argv){

    if(argc == 2 && strcmp(argv[1], "random") == 0){
        time_t t;
        srand((unsigned) time(&t));
        printf("%d%d %d%d", rand(), rand(), rand(), rand());
        return 0;
    }

    char line[1024];
    char *msg;
    int keep_running = 1;
    memset(line, 0, 1024);
    strcpy(NvimcomPort, "0");

    if(argc == 3 && getenv("NVIMR_PORT") && getenv("NVIMR_SECRET")){
        snprintf(line, 1023, "%scall SyncTeX_backward('%s', %s)", getenv("NVIMR_SECRET"), argv[1], argv[2]);
        SendToServer(getenv("NVIMR_PORT"), line);

        if(getenv("DEBUG_NVIMR")){
            FILE *df1 = fopen("/tmp/nclientserver_1_debug", "a");
            if(df1 != NULL){
                fprintf(df1, "%s %s %s %s\n", getenv("NVIMR_PORT"), getenv("NVIMR_SECRET"), argv[1], argv[2]);
                fclose(df1);
            }
        }
        return 0;
    }

    if(getenv("DEBUG_NVIMR")){
        df = fopen("/tmp/nclientserver_debug", "w");
        if(df){
            fprintf(df, "NVIMR_SECRET=%s\n", getenv("NVIMR_SECRET"));
            fflush(df);
        } else {
            fprintf(stderr, "Error opening \"nclientserver_debug\" for writing\n");
            fflush(stderr);
        }
    }

#ifdef WIN32
    // Set the value of NvimHwnd
    if(getenv("WINDOWID")){
#ifdef _WIN64
        NvimHwnd = (HWND)atoll(getenv("WINDOWID"));
#else
        NvimHwnd = (HWND)atol(getenv("WINDOWID"));
#endif
    } else {
        //fprintf(stderr, "$WINDOWID not defined\n");
        //fflush(stderr);
        // FIXME: Delete this code when $WINDOWID is implemented in NeovimQt
        NvimHwnd = FindWindow(NULL, "Neovim");
        if(!NvimHwnd){
            fprintf(stderr, "\"Neovim\" window not found\n");
            fflush(stderr);
        }
    }
#endif

    // Start the server
    if(!getenv("NVIMR_SECRET")){
        fprintf(stderr, "NVIMR_SECRET not found\n");
        fflush(stderr);
        exit(1);
    }
    strncpy(VimSecret, getenv("NVIMR_SECRET"), 127);
    VimSecretLen = strlen(VimSecret);

    // Finish immediately with SIGTERM
    signal(SIGTERM, HandleSigTerm);

#ifdef WIN32
    Sleep(1000);
#else
    sleep(1);
#endif

#ifdef WIN32
    Tid = _beginthread(NeovimServer, 0, NULL);
#else
    strcpy(myport, "0");
    pthread_create(&Tid, NULL, NeovimServer, NULL);
#endif

    while(fgets(line, 1023, stdin) && keep_running){
        if(df){
            msg = line;
            msg++;
            fprintf(df, "stdin: [%d] %s", (unsigned int)*line, msg);
            fflush(df);
        }

        for(unsigned int i = 0; i < strlen(line); i++)
            if(line[i] == '\n' || line[i] == '\r')
                line[i] = 0;
        msg = line;
        switch(*msg){
            case 1: // SetPort
                msg++;
#ifdef WIN32
                char *p = msg;
                while(*p != ' ')
                    p++;
                *p = 0;
                p++;
                strncpy(NvimcomPort, msg, 15);
#ifdef _WIN64
                RConsole = (HWND)atoll(p);
#else
                RConsole = (HWND)atol(p);
#endif
                if(msg[0] == '0')
                    RConsole = NULL;
#else
                strncpy(NvimcomPort, msg, 15);
#endif
                break;
            case 2: // Send message
                msg++;
                SendToServer(NvimcomPort, msg);
                break;
#ifdef WIN32
            case 3: // SendToRConsole
                msg++;
                SendToRConsole(msg);
                break;
            case 4: // SaveWinPos
                msg++;
                SaveWinPos(msg);
                break;
            case 5: // ArrangeWindows
                msg++;
                ArrangeWindows(msg);
                break;
            case 6:
                RClearConsole();
                break;
            case 7: // RaiseNvimWindow
                if(NvimHwnd)
                    SetForegroundWindow(NvimHwnd);
                break;
            case 11: // Check if R is running
                if(PostMessage(RConsole, WM_NULL, 0, 0)){
                    printf("call RWarningMsg('R was already started')\n");
                    fflush(stdout);
                } else {
                    printf("call CleanNvimAndStartR()\n");
                    fflush(stdout);
                }
                break;
#endif
            case 8: // Quit now
                keep_running = 0;
                break;
            default:
                fprintf(stderr, "Unknown command received: [%d] %s\n", line[0], msg);
                fflush(stderr);
                break;
        }
        memset(line, 0, 1024);
    }
#ifdef WIN32
    closesocket(Sfd);
    WSACleanup();
#else
    close(Sfd);
    SendToServer(myport, ">>> STOP Now <<< !!!");
    pthread_join(Tid, NULL);
#endif
    if(df)
        fclose(df);
    return 0;
}
Esempio n. 5
0
File: main.c Progetto: Jasu/HashTWM
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
  WNDCLASSEX winClass;
  HWND hwnd;
  MSG msg;

  // Process command line
  LPWSTR *argv = NULL;
  int argc;
  int i;
  unsigned short tilingMode;

  argv = CommandLineToArgvW(GetCommandLineW(), &argc);

  for (i = 0; i < argc; i++) {
    char arg[128];
    wsprintfA(arg, "%S", argv[i]);

    if (i < (argc - 1)) {
      char nextarg[128];
      wsprintfA(nextarg, "%S", argv[i + 1]);

      if (!strcmp(arg, "-o")) {
        alpha = atoi(nextarg);
      } else if (!strcmp(arg, "-i")) {
        if (ignoreCount < MAX_IGNORE) {
          sprintf(ignoreClasses[ignoreCount++], "%s", nextarg);
        }
      } else if (!strcmp(arg, "-a")) {
        include_mode = 1; // Include mode instead of exclude

        if (includeCount < MAX_IGNORE) {
          sprintf(includeClasses[includeCount++], "%s", nextarg);
        }
      } else if (!strcmp(arg, "-m")) {
        int y;
        modkeys = 0;

        for (y = 0; y < strlen(nextarg); y++) {
          switch (nextarg[y])
          {
            case 'c':
              modkeys |= MOD_CONTROL;
              break;
            case 'a':
              modkeys |= MOD_ALT;
              break;
            case 's':
              modkeys |= MOD_SHIFT;
              break;
            case 'w':
              modkeys |= MOD_WIN;
              break;
          }
        }
      } else if (!strcmp(arg, "-t")) {
        tilingMode = atoi(nextarg);
      } else if (!strcmp(arg, "-left")) {
        screen_x = atoi(nextarg);
      } else if (!strcmp(arg, "-top")) {
        screen_y = atoi(nextarg);
      } else if (!strcmp(arg, "-width")) {
        screen_width = atoi(nextarg);
      } else if (!strcmp(arg, "-height")) {
        screen_height = atoi(nextarg);
      }
    }
    if (!strcmp(arg, "-v")) {
      MessageBox(NULL, VERSION, "Version", MB_OK);
      LocalFree(argv);
      return 1;
    } else if (!strcmp(arg, "-l")) {
      lockMouse = 1;
    } else if (!strcmp(arg, "-x")) {
      experimental_mouse = 1;
    } else if (!strcmp(arg, "--one-tag")) {
      one_tag_per_window = 1;
    }
  }

  // Initialize tags
  for (i = 0; i < TAGS; i++) {
    tags[i].nodes = NULL;
    tags[i].last_node = NULL;
    tags[i].current_window = NULL;
    tags[i].tilingMode = DEFAULT_TILING_MODE;
    tags[i].masterarea_count = 1;
  }

  LocalFree(argv);

  winClass.cbSize = sizeof(WNDCLASSEX);
  winClass.style = 0;
  winClass.lpfnWndProc = WndProc;
  winClass.cbClsExtra = 0;
  winClass.cbWndExtra = 0;
  winClass.hInstance = hInstance;
  winClass.hIcon = NULL;
  winClass.hIconSm = NULL;
  winClass.hCursor = NULL;
  winClass.hbrBackground = NULL;
  winClass.lpszMenuName = NULL;
  winClass.lpszClassName = NAME;

  if (!RegisterClassEx(&winClass)) {
    MessageBox(NULL, "Error Registering Window Class", "Error", MB_OK | MB_ICONERROR);
    return 0; // Bail
  }

  hwnd = CreateWindowEx(0, NAME, NAME, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);

  if (!hwnd) {
    MessageBox(NULL, "Error Creating Window", "Error", MB_OK | MB_ICONERROR);
    return 0; // Bail
  }

  if (!screen_x && !screen_y && !screen_width && !screen_height) { // Screen options aren't being specified from the command line so set some defaults
    RECT workarea;
    SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea, 0);
    screen_x = workarea.left;
    screen_y = workarea.top;
    screen_width = workarea.right - workarea.left;
    screen_height = workarea.bottom - workarea.top;
  }

  RegisterHotkeys(hwnd);
  UpdateMousePos(hwnd);

  EnumWindows(EnumWindowsRestore, 0); // Restore windows on startup so they get tiled
  EnumWindows(EnumWindowsProc, 0);

  ArrangeWindows();

  // Get function pointer for RegisterShellHookWindow
  if ( RegisterShellHookWindow_ == NULL )
  {
    RegisterShellHookWindow_ = (BOOL (__stdcall *)(HWND))GetProcAddress(GetModuleHandle("USER32.DLL"), "RegisterShellHookWindow");
    if (RegisterShellHookWindow_ == NULL) {
      MessageBox(NULL, "Could not find RegisterShellHookWindow", "Error", MB_OK | MB_ICONERROR);
      return 0;
    }
  }

  RegisterShellHookWindow_(hwnd);
  shellhookid = RegisterWindowMessage("SHELLHOOK"); // Grab a dynamic id for the SHELLHOOK message to be used later

  while (GetMessage(&msg, NULL, 0, 0) > 0)
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }

  return msg.wParam;
}
Esempio n. 6
0
File: main.c Progetto: Jasu/HashTWM
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  node *current = NULL;
  node *nodes;
  unsigned short tag;

  switch (msg)
  {
    case WM_CREATE:
      if (experimental_mouse) {
        SetTimer(hwnd, TIMER_UPDATE_MOUSE, 500, NULL); // Poll for mouse position
      }
      break;

    case WM_CLOSE:
      {
        ClipCursor(0); // Release Cursor Lock
        DeregisterShellHookWindow(hwnd);
        UnregisterHotkeys(hwnd);
        if (experimental_mouse) {
          KillTimer(hwnd, TIMER_UPDATE_MOUSE); // Mouse Poll Timer
        }
        for (tag=0; tag<TAGS; tag++) {
          nodes = tags[tag].nodes;
          for (current = nodes; current;) {
            node *next = current->next;
            RestoreWindow(current->hwnd);
            RemoveNode(current->hwnd, tag);
            current = next;
          }
          DestroyWindow(hwnd);
        }
      }
      break;

    case WM_DESTROY:
      PostQuitMessage(WM_QUIT);
      break;

    case WM_HOTKEY:
      if (wParam >= KEY_TOGGLE_T1 && wParam < (KEY_TOGGLE_T1 + TAGS)) {
        ToggleTag(wParam - KEY_TOGGLE_T1);
        break;
      } else if (wParam >= KEY_SWITCH_T1 && wParam < (KEY_SWITCH_T1 + TAGS)) {
        MinimizeTag(current_tag);
        current_tag = wParam - KEY_SWITCH_T1;
        ArrangeWindows();
        break;
      }

      current = tags[current_tag].current_window;

      switch (wParam)
      {
        case KEY_SELECT_UP:
          if (current) {
            tags[current_tag].current_window = GetNextNode();
            FocusCurrent();
          }
          break;

        case KEY_SELECT_DOWN:
          if (current) {
            tags[current_tag].current_window = GetPreviousNode();
            FocusCurrent();
          }
          break;

        case KEY_MOVE_MAIN:
          SwapWindowWithNode(tags[current_tag].nodes);
          ArrangeWindows();
          break;

        case KEY_EXIT:
          PostMessage(hwnd, WM_CLOSE, 0, 0);
          break;

        case KEY_MARGIN_LEFT:
          margin -= 20;
          ArrangeWindows();
          break;

        case KEY_MARGIN_RIGHT:
          margin += 20;
          ArrangeWindows();
          break;

        case KEY_IGNORE:
          if (!disableNext) {
            disableNext = 1;
          } else {
            disableNext = 0;
          }
          break;

        case KEY_MOUSE_LOCK:
          if (lockMouse) {
            lockMouse = 0;
            ClipCursor(0);
          } else {
            lockMouse = 1;
            FocusCurrent();
          }
          break;

        case KEY_TILING_MODE:
          tags[current_tag].tilingMode = (tags[current_tag].tilingMode + 1) % 3;
          ArrangeWindows();
          break;

        case KEY_MOVE_UP:
          if (current) {
            SwapWindowWithNode(GetNextNode());
            ArrangeWindows();
          }
          break;

        case KEY_MOVE_DOWN:
          if (current) {
            SwapWindowWithNode(GetPreviousNode());
            ArrangeWindows();
          }
          break;

        case KEY_DISP_CLASS:
          {
            LPSTR temp = (LPSTR)malloc(sizeof(TCHAR) * 128);
            GetClassName(GetForegroundWindow(), temp, 128);
            MessageBox(NULL, temp, "Window Class", MB_OK);
            free(temp);
          }
          break;

        case KEY_TILE:
          if (IsGoodWindow(GetForegroundWindow())) {
            AddNode(GetForegroundWindow(), current_tag);
            ArrangeWindows();
          }
          break;

        case KEY_UNTILE:
          FullRemoveNode(GetForegroundWindow());
          ArrangeWindows();
          break;

        case KEY_INC_AREA:
          tags[current_tag].masterarea_count++;
          ArrangeWindows();
          break;

        case KEY_DEC_AREA:
          tags[current_tag].masterarea_count--;
          ArrangeWindows();
          break;

        case KEY_CLOSE_WIN:
          PostMessage(GetForegroundWindow(), WM_CLOSE, 0, 0);
          break;
      }
      break;

    case WM_TIMER:
      switch (wParam)
      {
        case TIMER_UPDATE_MOUSE:
          UpdateMousePos(hwnd);
          break;
      }
      break;

    default:
      if (msg == shellhookid) { // Handle the Shell Hook message
        switch (wParam)
        {
          case HSHELL_WINDOWCREATED:
            if (IsGoodWindow((HWND)lParam)) {
              AddNode((HWND)lParam, current_tag);
              ArrangeWindows();
              FocusCurrent();
            }
            break;

          case HSHELL_WINDOWDESTROYED:
            FullRemoveNode((HWND)lParam);
            ArrangeWindows();
            FocusCurrent();
            break;

          case HSHELL_WINDOWACTIVATED:
            {
              node *found = FindNode((HWND)lParam, current_tag);
              if (found) {
                tags[current_tag].current_window = current = found;
                FocusCurrent();
              }
            }
            break;
        }
      } else {
        return DefWindowProc(hwnd, msg, wParam, lParam);
      }
  }
  return 0;
}
Esempio n. 7
0
// COpenScrapeApp initialization
BOOL COpenScrapeApp::InitInstance()
{
	HMODULE		hMod;
	HANDLE		hProcess;
	DWORD		curprocid, aProcesses[1024], cbNeeded, cProcesses;
	char		sCurProcessName[MAX_PATH], sProcessName[MAX_PATH];

	// Classes
	if (!p_tablemap)  p_tablemap = new CTablemap;

	// Figure out our session number - get name of current process
	curprocid = GetCurrentProcessId();
	hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
                               PROCESS_VM_READ,
                               FALSE, curprocid );
	if (hProcess != NULL) {
		if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) {
			GetModuleBaseName( hProcess, hMod, sCurProcessName, MAX_PATH );
		}
	}
	CloseHandle(hProcess);

	// Noew look through process list and count number of matching processes
	EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded );
	cProcesses = cbNeeded / sizeof(DWORD);
	sessionnum = 0;
	for (int i=0; i<(int) cProcesses; i++) {
		hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
                               PROCESS_VM_READ,
                               FALSE, aProcesses[i] );
		if (hProcess != NULL) {
			if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) {
				GetModuleBaseName( hProcess, hMod, sProcessName, MAX_PATH );
			}
		}
		CloseHandle(hProcess);

		if (strcmp(sCurProcessName, sProcessName)==0) {
			sessionnum++;
		}
	}

	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	SetRegistryKey(_T("OpenScrape"));
	LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)
	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views
	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(COpenScrapeDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(COpenScrapeView));
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);
	// Enable DDE Execute open
	EnableShellOpen();
	RegisterShellFileTypes(TRUE);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line.  Will return FALSE if
	// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
	// call DragAcceptFiles only if there's a suffix
	//  In an SDI app, this should occur after ProcessShellCommand
	m_pMainWnd->DragAcceptFiles();

	// Start tablemap dialog
	m_TableMapDlg = new CDlgTableMap(NULL);
	// Create a desktop-based window, no longer a dialog-based one (BillW)
	// http://www.maxinmontreal.com/forums/viewtopic.php?f=112&t=16464
	m_TableMapDlg->Create(CDlgTableMap::IDD, CWnd::GetDesktopWindow());
	m_TableMapDlg->ShowWindow(SW_SHOW);
  ArrangeWindows();
	return true;
}